Create a PostgreSQL Schema Before Running Laravel Migrations

Laravel cannot create its migrations repository inside a PostgreSQL schema that does not exist. If the connection uses a non-default search_path, provision that schema before running php artisan migrate. Do this as an environment setup step, not inside a migration that Laravel cannot reach yet.

Last updated: November 19, 2026.

CREATE ROLE app_migrator LOGIN PASSWORD 'use-a-secret-from-your-vault';
CREATE ROLE app_runtime LOGIN PASSWORD 'use-a-different-secret';

CREATE SCHEMA IF NOT EXISTS app AUTHORIZATION app_migrator;
GRANT USAGE ON SCHEMA app TO app_runtime;

Run this through your database provisioning system with an administrative role. Do not keep literal passwords in a checked-in SQL file. The migration role owns the schema; the runtime role receives only the access the application actually needs.

Why the first migration fails

Laravel’s PostgreSQL connector configures search_path when it opens the connection. The framework then checks for or creates its migrations table. A current Laravel 13 report shows this failing when the first schema in that path has not been created. The issue is still under review, so do not assume Laravel will provision arbitrary schemas automatically.

PostgreSQL treats a schema as a namespace. Its CREATE SCHEMA documentation explains that unqualified objects are created in the first suitable schema on the search path and that creating a schema requires the database-level CREATE privilege. That provisioning step necessarily comes before Laravel can create its migration metadata there.

Keep identifiers and privileges controlled

Set the Laravel connection’s search_path to a fixed configuration such as app,public only after app exists. Avoid concatenating an environment value into CREATE SCHEMA: bound parameters do not quote SQL identifiers, and an unchecked value can become SQL injection. If environments use different schema names, validate each against an allowlist and quote it with a PostgreSQL-aware identifier function in the provisioning tool.

Run migrations with the owner or a dedicated migration role. Grant the runtime role USAGE plus specific table, sequence and function privileges after objects exist; it normally does not need permission to create or alter tables. In a fresh-environment test, connect with the migration credentials, confirm SHOW search_path and SELECT current_schema(), run migrations, then verify the migrations table and application tables were created under the intended schema.

Related Web Cheat Sheet guides

Sergey Kornilov

Sergey Kornilov