Ad

How To Define Schema Migration Laravel Postgres?

- 1 answer

Im using a multitenant package in Laravel called Laravel Tenancy and i change the setting to work with SCHEMA, every tenant has your schema right?

Well i'm using postgres and I'd like to change 'public' the default schema, i'd like to use maindatabase.

I have changed it in:

'connections' => [
        'pgsql' => [
            'driver' => 'pgsql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
            'schema' => 'maindatabase',
            'sslmode' => 'prefer',
        ],
]

But when I execute php artisan migrate i have this error:

Illuminate\Database\QueryException : SQLSTATE[3F000]: Invalid schema name: 7 ERROR: no schema has been selected to create in at character 14 (SQL: create table "migrations" ("id" serial primary key not null, "migration" varchar(255) not null, "batch" integer not null))

How can I fix it? Thank you

Ad

Answer

Make sure you have all USAGE privilege to that schema, i.e.:

GRANT USAGE ON SCHEMA maindatabase TO your_username;
Ad
source: stackoverflow.com
Ad