简体   繁体   English

Laravel 5.5 中的迁移:无法声明类,因为名称已被使用

[英]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:请尝试以下步骤:

  1. Delete all tables (clear your database)删除所有表(清除数据库)
  2. Verify if you really doesn't have duplicated migration classes验证您是否真的没有重复的迁移类
  3. Verify if all of your migrations has date and time on their filenames验证您的所有迁移文件名是否都有日期和时间
  4. Run composer dumpautoload运行composer dumpautoload
  5. Run php artisan migrate运行php artisan migrate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误迁移:无法声明类 X,因为该名称已在使用中 - Error migrations: Cannot declare class X, because the name is already in use laravel - 无法声明类 Carbon\\Carbon,因为该名称已被使用 - laravel - Cannot declare class Carbon\Carbon, because the name is already in use Laravel 9 - 无法声明类 CreateUsersTable,因为该名称已在使用中 - Laravel 9 - Cannot declare class CreateUsersTable, because the name is already in use Laravel 无法声明 class 因为该名称已被使用 - Laravel cannot declare class because the name is already in use 无法声明类,因为名称已被使用 - Cannot declare class, because the name is already in use Laravel 无法声明类 Symfony\\Component\\HttpFoundation\\AcceptHeader,因为名称已被使用 - Laravel Cannot declare class Symfony\Component\HttpFoundation\AcceptHeader, because the name is already in use 无法声明类mPDF,因为该名称已被使用 - Cannot declare class mPDF, because the name is already in use 无法声明类“ TestCommandRun”,因为该名称已被使用 - Cannot declare class 'TestCommandRun', because the name is already in use 致命错误:无法声明类 ProductFilterIterator,因为该名称已在 - Fatal error: Cannot declare class ProductFilterIterator, because the name is already in use in 无法声明 class,因为该名称已在(同一文件)中使用 - Cannot declare class because the name is already in use in (same file)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM