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

nahin14's avatar

Table already exists error

Hi, i'm getting an error when i deploy my application.

[PDOException]
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'insurers' already exists

This error started occuring after i made some changes to the the migration files in Github.

So I tried deleting the application & rolling back migrations as well as deleting the git repository itself in Github.

I then created the application as well as Github git repository again and set them both up, but still got the same error.

0 likes
7 replies
bestmomo's avatar

Check if the rollback is ok. If not clean directly the database and use migrate to create your tables. And also correct your migration down methods.

4 likes
isaackearl's avatar

is this an app you are developing? Or is it live? If it is in development, then simply drop the database schema and then recreate and then run your migrations again.

drop database <databasename>;
create database <databasename>;

It's ok to modify migration files and drop and rebuild etc while you are in development. Once your app is in production, then you should always create a new migration for the changes you want to make.

If your site is currently live.. then I would suggest doing a bit of research about migrations in laravel, and then looking at the migrations table on your database. Laravel makes this migration table that stores information about your migrations so that it knows how to rollback what you've done, and which migrations need to run, and which have already run. If you changed a migration that has already been run, then this screws stuff up. You may have to modify some rows or something to get it to run the migrations you want etc.

to fix your specific problem you may want to add a row to the migrations table for the insurers table, so that when you do a migraiton:rollback it will actually drop the table.

another possibility is that you forgot to add the drop table to your insurers migration.

4 likes
nahin14's avatar

Thank you for all your help. Yes it is in production at the moment. The problem was that it was not dropping the insurers table because of the change in the migration.

avescasio's avatar

I have the same problem too, and I found the culprit of this problem.

I have created my tables by using this command "php artisan migrate:refresh" instead of php artisan migrate.

You should have to record first the migration raw file in migrations table by using the command "php artisan migrate" before using the command "php artisan migrate:refresh" and also you need to correct the down method just like what bestmomo said.

1 like
Alaa15's avatar

You can delete your all table from phpmyadmin , and do the migration again, it will work

2 likes
arslanramay's avatar

I had the same problem and I just did a simple trick to solve the issue.

Simply delete your current database and run your migrations again.

drop database <your_db_name>;
create database <your_db_name>;
Cronix's avatar

@arslanramay That's fine in dev, but not so good for a production db that has data.

The real key is once your db is in production, don't edit existing migration files. If you need to make a change/alter a table, add a new migration and do the change there - not in the original migration file.

Please or to participate in this conversation.