SQLSTATE[42P07]: Duplicate table: 7 ERROR: relation "migrations" already exists
Solution 1
The actual solution is to append 'schema' => 'public',
to the end of the psql DB_CONNECTION.
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST'),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'schema' => 'public', <------- ADD HERE
],
Now, php artisan migrate
works perfectly fine.
Solution 2
It is an old question but i faced this problem recently and it seems after copying my migration table from another database owner is changed.
So check your database and table owners and make sure tables owned by same user.
code-8
I'm B, I'm a cyb3r-full-stack-web-developer. I love anything that is related to web design/development/security, and I've been in the field for about ~9+ years. I do freelance on the side, if you need a web project done, message me. ;)
Updated on June 08, 2022Comments
-
code-8 almost 2 years
- Laravel Version: 5.1
- PHP Version:5.6
- Database Driver & Version: psql
Description:
I run
php artisan migrate
the first time, and it work perfectly fine.Then:
I've added 1 more migration script to alter one of my table.
As soon as I ran
php artisan migrate
, I started to see this error.
I have this setting in my database.php
'default' => env('DB_CONNECTION', 'pgsql'), 'pgsql' => [ 'driver' => 'pgsql', 'host' => env('DB_HOST'), 'database' => env('DB_DATABASE'), 'username' => env('DB_USERNAME'), 'password' => env('DB_PASSWORD'), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, ],
Please kindly let me know what else, I can provide.
-
Eduardo almost 3 yearsAnd where do you start checking? I have my project hosted on Heroku
-
xuma almost 3 yearsYou can check with this command;
SELECT * FROM pg_catalog.pg_tables WHERE schemaname != 'pg_catalog' AND schemaname != 'information_schema';
-
Arno van Oordt about 2 yearsSame issue here.. when copying production db to staging the tables in the staging still had the owner of the production db. After copying the db I run this command on the new staging db:
REASSIGN OWNED BY production_user TO staging_user;