5

I meesed up my Laravel migrations and I get PHP Fatal error: Cannot redeclare Class when running

php artisan migrate --path="workbench/fefe/feeds2go/src/migrations"

I have been deleting the migration file and dropping manually the table and recreated with php artisan migrate:make but still the same.

How can I fix migratons?

fefe
  • 8,755
  • 27
  • 104
  • 180

4 Answers4

13

You need to check all of your migration class files and check for duplicate class names.

lowerends
  • 5,469
  • 2
  • 24
  • 36
  • Is it possible to get this error in laravel when you don't have other migrations with this same class name? – Josh R. Jan 29 '16 at 21:59
  • @JoshR., yes it's possible. try composer dump-autoload and see if it works. reference: https://github.com/laravel/framework/issues/8782#issuecomment-145324891 – osiris May 24 '16 at 15:51
0

"Cannot redeclare class" happens when the class name appears at least 2 times.

The easiest way to do it is to run either composer install or composer.phar dump-autoload. It will generate warning information for you to identify which class is duplicated. Then, simply remove the class that declared twice.

Here is the error I got after I ran php artisan migrate

[Symfony\Component\Debug\Exception\FatalErrorException]   
Cannot redeclare class CreateKidTimeslotTable

Therefore, I use composer.phar dump-autoload to identify the error.

 Warning: Ambiguous class resolution, "CreateKidTimeslotTable" was found in both "laravel/database/migrations/2016_05_23_024341_create_kid_timeslot_table.php" and "laravel/database/migrations/2016_08_24_022635_create_kid_time_slot_table.php", the first will be used.

Remove the duplicated table that you don't need anymore.

Fred Lai
  • 1,131
  • 10
  • 21
0

You need to delete that migration file manually from the migration directory of your project and also, delete it's entry from the migration table in the database or you can run the php artisan migrate:refresh but it will drop your all table data so also add the your step with php artisan migrate:refresh --step=n

0

This is a late answer, but probably this would solve your issue.

  1. Go to app/storage/migrations.
  2. Delete the migration file that causes the error (You can also delete everything stored there).
  3. Done.
Blues Clues
  • 1,694
  • 3
  • 31
  • 72