Skip to content
Advertisement

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:

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

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.

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement