简体   繁体   中英

How to use migrate specific or self-defined schema using laravel in postgresql

I'm using PostgreSQL with Laravel. I have created a new Schema in my postgresql Database and setup pgsql driver in my laravel project. But when I migrate all migration by-default load in public Schema. I want to load all migration in self-defined Schema . How Can I do this.

Here, my .env and app/config/database file configuration.

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:qqv8sHot0EBDj4fZXedwaxY4Xb+O4ynEzLgyKTLtW88=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=dbtuto
DB_USERNAME=postgres
DB_PASSWORD=root

app/config/database file configuration.

 'pgsql' => [
        'driver' => 'pgsql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '5432'),
        'database' => env('DB_DATABASE', ''),
        'username' => env('DB_USERNAME', ''),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'prefix' => '',

        'schema' => 'dbtutoschema',
        'sslmode' => 'prefer',
    ],

Note: dbtutoschema is my self-defined schema I want to load all migration under this Schema.

Set the search_path in a general statement .

// Retrieve the current search path in a select query
$sp_res = DB::select('SHOW search_path');
$current_search_path = $sp_res[0]->search_path;

// Set a new search path
$search_path = 'my_schema';
DB::statement("SET search_path TO $search_path");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM