phplaravellaravel-5database-migration

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


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.


Solution

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