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

kevbrn's avatar
Level 14

migrate tries to execute already migrated migrations

That's a tongue twister... Occasionally when I run php artisan migrate it attempts to run migrations that have already been executed thus throwing a Base table or view already exists. To work around this I usually delete the offending migration but Id prefer to keep them around. How are migrations tracked? Does it just check against the migrations table?

Currently I'm running into this issue with a migration that was generated from a third party package and I don't have a migration file in the migration folder. I assume its in the vendor folder somewhere?

Thanks!

0 likes
4 replies
topvillas's avatar

Does the package have a publish command?

If it does it should put the migrations in the right place.

Thyrosis's avatar
Thyrosis
Best Answer
Level 17

If the migration hasn't been run but the table already exists (maybe from a package or an export from a different environment), you can manually add the migration to the migrations table.

Just copy the last one in the table and update the name to reflect the name of the migration you want to skip.

You should never have to delete migration files! How will you ever install your application on a different server or computer?

kevbrn's avatar
Level 14

Thanks @topvillas and @Thyrosis

@Thyrosis - I'll give that a try. Anytime I need to recreate the app I would just export the db and re-import where needed but I agree keeping those files is ideal. Any ideas why they wouldn't get tracked in the first place?

Thanks!

Thyrosis's avatar

I get it sometimes when there is an error in one of the migrations and the migrate command dies from the exception. Then when I rerun the migrations, some tables have been created but haven't been saved to the migrations table, thus resulting in the 'table already exists' error.

Or, when manually exporting some table from one environment and importing it in another, without also exporting the migration entry. Or when you've manually created a table before creating or running the migration.

Recreating the app would only work if you still have a working copy of it, including the database. But when a server would crash and you've lost your database too, that would be problematic.

Please or to participate in this conversation.