Safely remove migration In Laravel
I accidentally created a migration with a bad name (command: php artisan migrate:make
). I did not run (php artisan migrate
) the migration, so I decided to remove it.
My steps:
- Manually delete the migration file under
app/database/migrations/my_migration_file_name.php
- Reset the composer autoload files:
composer dump-autoload
- Relax
If you did run the migration (php artisan migrate
), you may do this:
a) Run migrate:rollback
- it is the right way to undo the last migration (Thnx @Jakobud)
b) If migrate:rollback
does not work, do it manually (I remember bugs with migrate:rollback in previous versions):
- Manually delete the migration file under
app/database/migrations/my_migration_file_name.php
- Reset the composer autoload files:
composer dump-autoload
- Modify your database: Remove the last entry from the migrations table
DO NOT run php artisan migrate:fresh
that's gonna drop all the tables
You likely need to delete the entry from the migrations table too.
If the migration has been run (read: migrated) then you should roll back your migration to clear the history from your database table. Once you're rolled back you should be able to safely delete your migration file and then proceed with migrating again.