Laravel migration - multiple migrations (files) at a time

Let's say I have several migration files updating a single table.

eg.

  2016_03_20_072730_create_tasks_table.php
 2016_03_20_075467_create_tasks_table.php

... that came from the repo by different team members. Everyone sets up something in a table, for example. adding a column.

When I try:

  php artisan migrate 

I get an error:

  PHP Fatal error: Cannot declare class CreateTasksTable, because the name is
 eady in use in U: \ www \ b10 \ database \ migrations \ 2016_03_20_072737_create_tasks_
 le.php on line 30


   [Symfony \ Component \ Debug \ Exception \ FatalErrorException]
   Cannot declare class CreateTasksTable, because the name is already in use

How can I deal with the situation described above?

EDIT

Here is the code:

2016_03_20_072730_create_tasks_table.php:

  class CreateTasksTable extends Migration
 {
     / **
      * Run the migrations.
      *
      * @return void
      * /
     public function up ()
     {
        Schema :: table ('tasks', function ($ table)
        {
            $ table-> string ('task1');
        });
     }

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

2016_03_20_075467_create_tasks_table.php:

  class CreateTasksTable extends Migration
 {
     / **
      * Run the migrations.
      *
      * @return void
      * /
     public function up ()
     {
     Schema :: table ('tasks', function ($ table)
         {
             $ table-> string ('task2');
         });
     }

     / **
      * Reverse the migrations.
      *
      * @return void
      * /
     public function down ()
     {
         Schema :: drop ('tasks');
     }
 }
+7
php migration laravel
source share
1 answer

Each migration must have a unique class name. Rename the second one to something more reasonable, for example 2016_03_20_075467_add_task2_to_tasks_table and AddTask2ToTasksTable , then run composer dump-autoload so that Laravel finds the changes. Now you can migrate.

Edit: now that both migration codes have been edited in the question, I see that the first migration has the same problem and should be renamed in the same way. You can probably create a migration first. You should stop calling migration editing anything with create , since you are not actually creating a table.

+7
source share

All Articles