我陷入了Laravel迁移,并且收到PHP致命错误:运行时无法重新声明类
php artisan migrate --path="workbench/fefe/feeds2go/src/migrations"
我已经删除了迁移文件并手动删除了表,并使用php artisan migrate:make
重新创建,但仍然相同。
如何解决偏头痛?
您需要检查所有迁移类文件,并检查重复的类名。
“无法重新声明班级”发生在班级名称至少出现2次。
最简单的方法是运行composer install
或composer.phar dump-autoload
。它将生成警告信息,以供您标识重复的类。然后,只需删除声明两次的类即可。
这是我运行php artisan迁移后遇到的错误
[Symfony\Component\Debug\Exception\FatalErrorException]
Cannot redeclare class CreateKidTimeslotTable
因此,我使用composer.phar dump-autoload
来识别错误。
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.
删除不再需要的重复表。
您需要从项目的迁移目录中手动删除该迁移文件,并且从数据库的迁移表中删除该条目,或者可以运行php artisan migrate:refresh
,但是它将删除所有表数据,因此还要添加php artisan migrate:refresh --step=n
]迈出的第一步
这是一个较晚的答案,但这可能会解决您的问题。