Skip to content

Laravel 9, Postgres can't change search_path to valid schema #41062

Closed
@xorock

Description

@xorock
  • Laravel Version: 9.1.0
  • PHP Version: 8.1.2
  • Database Driver & Version: PostgreSQL 14.1 (Debian 14.1-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit

Description:

I am trying to change the search_path to the current schema and unfortunately neither queries nor migrations work. Laravel fails to connect to the database on the defined schema.

Steps To Reproduce:

  • create new laravel 9 project
  • change driver to pgsql
  • create test-db schema
  • change database.php, postgres setting to 'search_path' => 'test-db',
  • try to run migration or select query from database

dd(DB::getPdo()->query('select current_schemas(true)')->fetchAll());

^ array:1 [[▼]()
  0 => array:2 [[▼]()
    "current_schemas" => "{pg_catalog}"
    0 => "{pg_catalog}"
  ]
]
php artisan migrate

   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))

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
    708▕         // If an exception occurs when attempting to run a query, we'll format the error
    709▕         // message to include the bindings with SQL, which will make this exception a
    710▕         // lot more helpful to the developer instead of just the database's errors.
    711▕         catch (Exception $e) {
  ➜ 712▕             throw new QueryException(
    713▕                 $query, $this->prepareBindings($bindings), $e
    714▕             );
    715▕         }
    716▕     }

      +37 vendor frames
  38  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions