Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLSTATE[42P07]: Duplicate table: 7 ERROR: relation "migrations" already exists

  • 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.

enter image description here


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.

like image 557
code-8 Avatar asked Oct 23 '25 18:10

code-8


2 Answers

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.

like image 128
xuma Avatar answered Oct 26 '25 07:10

xuma


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.

like image 36
code-8 Avatar answered Oct 26 '25 07:10

code-8