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

treadnought's avatar

Forge deployment fails on migration

My deployment fails with the message SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'sessions' already exists i.e. it's trying to run migrations when there should be nothing to migrate.

In local development running ./vendor/bin/sail php artisan migrate gives the expected response of nothing to migrate

I've tried deleting the site from Forge and redeploying, which works the first time but then fails again. Is there anything I can do to let Forge know there's nothing to migrate?

0 likes
5 replies
treadnought's avatar

Yes, that works but prevents any future migrations. As soon as I replace the migrate command in the deploy script I get the same error.

treadnought's avatar
treadnought
OP
Best Answer
Level 9

I managed to fix the problem, so just in case anyone else gets into this muddle here's the problem and solution:

I'd absentmindedly made some changes directly to the database (I come from a MS Access background, IKR), so the migration pattern was disrupted somehow. On my local machine artisan migrate:status showed all migrations as Ran. On the remote machine only the boilerplate migrations showed yes, with all mine showing no, even though all the tables were present in the production database. This of course resulted in a Table already exists error when the Forge deploy script tried to run migrate.

I solved the problem by deleting all the tables in the production database, then running migrate on the remote server via the command line. Restoring the database from a backup (via TablePlus) unfortunately also restored the problem, so I extracted just the INSERT statements from the database dump and imported them.

Now the site is back up & running and I can make more migrations :D

EchelonStudio's avatar

that is because when you first try to run the migration some of your migration was successfully migrated to the database while some don't maybe because of some error so when you try to run the php artisan migrate again it might yell at you that nothing to migrate so you have to use php artisan migrate --force or php artisan migrate:fresh these commands will drop all the tables and run a fresh migration... note: you must have solve why its not migrating in the first place .I hope it helps

treadnought's avatar

I note that php artisan migrate --force is run by default in any deployment, so running that again would not help. php artisan migrate:fresh will of course run all the migrations again, so there's a complete set of tables with no data. At that point php artisan migrate:status will show all migrations (correctly) with Yes in the "Ran" column.

The problem was then how to get the data back into the tables - as mentioned above, running a backup restore via TablePlus put all the data back, but then php artisan migrate:status for some reason shows my migrations with No in the "Ran" column. The only way to get the data back was to import the SQL insert statements (i.e. from the backup but without the DROP TABLE IF EXISTS and CREATE TABLE statements).

Hope this is a bit clearer.

Please or to participate in this conversation.