3

I am using composer for migrating two tables like this:

php artisan make:migration create_two_tables --create="projects","tasks"

Its creating the file in database->migration folder.

but while migrating using

php artisan migrate

its creating only table in database like this:

'projects,tasks'

as one table.

I want only one file and only one command like what I do in the top for migrating two tables in db.

Is there any possibility to get this?

Note: My superior ordered me to not change the database migration file at any cost...

Can anyone help me out here...

2 Answers 2

3

The make:migration command is just to create a new migration file from a template. To actually define the migration you normally have to edit that file. So in your case you would do this:

php artisan make:migration create_two_tables --create="projects"

Then open the ***_create_two_tables.php migration file and add the second table:

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('projects', function(Blueprint $table)
    {

    });

    Schema::create('tasks', function(Blueprint $table)
    {

    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::drop('projects');
    Schema::drop('tasks');
}

Usually you also want to add actual columns to your tables. And that you do inside the Schema::create closure:

Schema::create('projects', function(Blueprint $table)
{
    $table->increments('id');
    $table->string('name');
    // and so on
});

Read more about creating tables with the Schema Builder here

Sign up to request clarification or add additional context in comments.

2 Comments

I did this already, and I want through command prompt to create this tables, Is there any possibility like that
Not without your own command. But it is it that hard to open a file and copy paste + change the table name?
1

If you want to just create two tables through artisan and not add any columns to those tables you can create two migrations. Create one for each table. When you run

 php artisan make:migration create_projects_table --create=projects    
 php artisan make:migration create_tasks_table --create=tasks
 php artisan migrate 

it will execute both migrations and create both tables for you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.