2

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

1 Answer 1

1

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");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.