[英]Migrations in Laravel 5.5: Cannot declare class because the name is already in use
While running a migration in Laravel I got an error:在 Laravel 中运行迁移时出现错误:
PHP Fatal error: Cannot declare class UpdateEnquiriesTable, because the name is already in use in /var/www/project/database/migrations/2018_01_17_160335_update_enquiries_table.php on line 33
PHP 致命错误:无法声明类 UpdateEnquiriesTable,因为该名称已在第 33 行的 /var/www/project/database/migrations/2018_01_17_160335_update_enquiries_table.php 中使用
Having done a bit of research, I see that each migration file needs a unique class name (I don't remember mention of that before, but that could be me).做了一些研究后,我发现每个迁移文件都需要一个唯一的类名(我不记得之前提到过,但那可能是我)。
According to another question, the recommendation is to change the name of one of the classes .根据另一个问题,建议更改其中一个类的名称。
But then someone else recommends deleting the conflicting migrations .但是其他人建议删除冲突的迁移。
Which would be the preferred option?哪个是首选? Assuming either are valid.
假设两者都有效。
You can change one of the class names and then manually update it's entry in the migrations table to preserve your database state.您可以更改类名之一,然后手动更新它在迁移表中的条目以保留您的数据库状态。 If you delete the conflicting migrations you may run into problems on subsequent migrations and/or rollbacks since the class in question no longer exists.
如果您删除冲突的迁移,您可能会在后续迁移和/或回滚中遇到问题,因为相关类不再存在。
Simply delete this file and retype the migration.只需删除此文件并重新键入迁移即可。 That table is already registered in your migration table so this table will be created even without this file
该表已在您的迁移表中注册,因此即使没有此文件也会创建该表
Please try the following steps:请尝试以下步骤:
composer dumpautoload
composer dumpautoload
php artisan migrate
php artisan migrate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.