'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.
Solution 1:[1]
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
Solution 2:[2]
Please try the following steps:
- Delete all tables (clear your database)
- Verify if you really doesn't have duplicated migration classes
- Verify if all of your migrations has date and time on their filenames
- Run
composer dump-autoload - Run
php artisan migrate
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rock Dial |
| Solution 2 | dipenparmar12 |
