golang-migrate/migrate · error
no schema
Error message
no schema
What it means
ErrNoSchema means pgx could not determine the PostgreSQL schema for migrations. It is raised when config.SchemaName is empty AND the session's CURRENT_SCHEMA() returns an empty string (pgx.WithInstance line 108-110; same check in WithConnection and Open, and in pgx/v5). Normally CURRENT_SCHEMA() falls back to 'public', so this error indicates an unusual session state.
Source
Thrown at database/pgx/pgx.go:50
func init() {
db := Postgres{}
database.Register("pgx", &db)
database.Register("pgx4", &db)
}
var (
multiStmtDelimiter = []byte(";")
DefaultMigrationsTable = "schema_migrations"
DefaultMultiStatementMaxSize = 10 * 1 << 20 // 10 MB
DefaultLockTable = "schema_lock"
DefaultLockStrategy = LockStrategyAdvisory
)
var (
ErrNilConfig = fmt.Errorf("no config")
ErrNoDatabaseName = fmt.Errorf("no database name")
ErrNoSchema = fmt.Errorf("no schema")
ErrDatabaseDirty = fmt.Errorf("database is dirty")
)
type Config struct {
MigrationsTable string
DatabaseName string
SchemaName string
LockTable string
LockStrategy string
migrationsSchemaName string
migrationsTableName string
StatementTimeout time.Duration
MigrationsTableQuoted bool
MultiStatementEnabled bool
MultiStatementMaxSize int
}
type Postgres struct {View on GitHub (pinned to 01a9643f14)
Solutions
- Set config.SchemaName explicitly (e.g. "public" or your target schema) in the pgx.Config
- Ensure the connection has a valid search_path (do not override it to empty in the DSN)
- Confirm the role can access the schema and the schema exists (CREATE SCHEMA if needed)
Example fix
// before
cfg := &pgx.Config{ DatabaseName: "app" } // SchemaName empty
// after
cfg := &pgx.Config{ DatabaseName: "app", SchemaName: "public" } Defensive patterns
Strategy: validation
Validate before calling
if cfg.SchemaName == "" {
var s string
if err := db.QueryRow("SELECT CURRENT_SCHEMA()").Scan(&s); err != nil || s == "" {
cfg.SchemaName = "public" // or fail fast with a clear message
}
} Try / catch
drv, err := pgx.WithInstance(db, cfg)
if errors.Is(err, pgx.ErrNoSchema) {
return fmt.Errorf("no schema: set cfg.SchemaName explicitly or fix search_path: %w", err)
} Prevention
- Always set SchemaName explicitly instead of relying on CURRENT_SCHEMA()
- Do not blank the search_path via DSN options
- After Postgres 15 upgrades, verify the role's CREATE/USAGE privileges on the public schema
When it happens
Trigger: Calling pgx.WithInstance/WithConnection/Open with an empty config.SchemaName while the connection's current schema is unset or empty — e.g. search_path cleared via options, a revoked public schema, or a stripped-down connection role.
Common situations: Connecting with a restricted role where public schema was dropped (Postgres 15+ default behavior change); setting search_path='' in DSN options; cloning connections in pooled environments without a search_path.
Related errors
AI-assisted analysis of golang-migrate/migrate@01a9643f14 (2026-09-02).
Data as JSON: /api/errors/5a5863a486fbbb5e.
Report an issue: GitHub.