Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Robinvm's avatar

Deleting a migration

Hello, i want to delete a migration file but when i did i cannot migrate:refresh again because it cannot find the deleted file, how can i properly do this?

0 likes
10 replies
ejdelmonico's avatar

If you can't recover the migration file, you could recreate it and then roll it back or you could just use SQLpro and remove what you need to if all else fails.

WebKenth's avatar

@ejdelmonico he would have to remember the timestamp from the migration file if he were to recreate it.

Rule one of migration, never delete your migration files if you have migrated them.

You will have to manually go in and delete the table it created and remove the migration from the migration's table.

Here's what you can do.

  • Look at your migrations table and find the migration you deleted
  • create a new migration with the name of the deleted migration (add the timestamps from the migrations table
  • run php artisan migrate:rollback
  • delete the migration and continue

Alternatively you could:

  • manually go into your database and delete every table (disable integrity checks) and migrate again

If you are on a production server with valuable data do not choose option #2

ejdelmonico's avatar

The timestamp is in the DB in the migrations table at the start of the migration name.

@Robinvm What system are you on? You can probably recover the deleted file.

Robinvm's avatar

@ejdelmonico i recoverd the files and putted them back in the folder, how can i delete the migration now? including the file

davorminchorov's avatar

You can delete the file and the record with the same filename from the migrations table and it should not cause any troubles.

3 likes
clay's avatar

For future reference, rollback past the migration you want to delete, before deleting the migration. Just make sure that more recent migrations don't depend on the migration you're deleting.

ejdelmonico's avatar

php artisan migrate:rollback and then after you get the DB where you want it, you can delete the migration file again.

1 like
sl0wik's avatar

Tip: After deleting migration files you might need to do composer dump-autoload

7 likes

Please or to participate in this conversation.