Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default postgresql schema for laravel?

I created new postgresql user:

CREATE ROLE lara_user SUPERUSER LOGIN PASSWORD 'mypassword';

Then create schema which is owned by this user

CREATE schema lara AUTHORIZATION lara_user;

In Laravel's .env file I have

DB_DATABASE=postgres
DB_USERNAME=lara_user
DB_PASSWORD=mypassword

Laravel don't sees schema lara and still connected to public schema.

How can I change and set default schema lara for Laravel ?

like image 856
Oto Shavadze Avatar asked Jul 21 '17 16:07

Oto Shavadze


People also ask

How do I create a default schema in PostgreSQL?

The output will be, After creating a new schema, you can make it a default schema instead of a public schema. To make a schema default, the search_path variable is used. Search_path variable defines the schema order in which they are searched when an object is referenced without any schema name.

What is the default schema in PostgreSQL?

Whenever a new database is instantiated, a default schema named “public” is created. The contents of a schema include all the other database objects such as tables, views, stored procedures, triggers, and etc.

Which schema type is always created as default in PostgreSQL?

Every database starts out with one schema, the public schema. Inside that schema, the default install of PostGIS creates the geometry_columns , geography_columns and spatial_ref_sys metadata relations, as well as all the types and functions used by PostGIS. So users of PostGIS always need access to the public schema.

Can I use Laravel with PostgreSQL?

As of the time of this writing, the latest available version of Laravel is 6.0 LTS, and can be used with any supported version of PostgreSQL. In reality, Laravel can be used with any of several database engines because of the underlying Eloquent ORM.


1 Answers

in app/config/database.php

'pgsql' => array(
            'driver'   => 'pgsql',
            'host'     => 'localhost',
            'database' => 'forge',
            'username' => 'forge',
            'password' => '',
            'charset'  => 'utf8',
            'prefix'   => '',
            'schema'   => 'public',
        ),

in new version of laravel change

'schema'   => 'public',

to

'search_path' => 'public',
like image 108
Exprator Avatar answered Oct 26 '22 12:10

Exprator