golang-migrate/migrate · error
no database name
Error message
no database name
What it means
The yugabytedb driver returns ErrNoDatabaseName ('no database name') when the provided config has an empty DatabaseName. The driver needs to know which YSQL database to connect to in order to create/check the migrations table. It is a public sentinel comparable with errors.Is.
Source
Thrown at database/yugabytedb/yugabytedb.go:32
"github.com/cenkalti/backoff/v4"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database"
"github.com/jackc/pgconn"
"github.com/jackc/pgerrcode"
"github.com/lib/pq"
)
const (
DefaultMaxRetryInterval = time.Second * 15
DefaultMaxRetryElapsedTime = time.Second * 30
DefaultMaxRetries = 10
DefaultMigrationsTable = "migrations"
DefaultLockTable = "migrations_locks"
)
var (
ErrNilConfig = errors.New("no config")
ErrNoDatabaseName = errors.New("no database name")
ErrMaxRetriesExceeded = errors.New("max retries exceeded")
)
func init() {
db := YugabyteDB{}
database.Register("yugabyte", &db)
database.Register("yugabytedb", &db)
database.Register("ysql", &db)
}
type Config struct {
MigrationsTable string
LockTable string
ForceLock bool
DatabaseName string
MaxRetryInterval time.Duration
MaxRetryElapsedTime time.Duration
MaxRetries intView on GitHub (pinned to 01a9643f14)
Solutions
- Set cfg.DatabaseName (or include the database in the Open URL, e.g. yugabytedb://host/dbname) before creating the driver.
- Validate the config before the call: if cfg.DatabaseName == "" return a clear error early.
- Check env/flag plumbing that supplies the database name (env var may be unset).
- Compare errors.Is(err, yugabytedb.ErrNoDatabaseName) to pinpoint the missing field.
- If passing to WithInstance after parsing a URL, use the same name used to open the sql.DB connection.
Example fix
// before
cfg := &yugabytedb.Config{}
m, err := yugabytedb.WithInstance(session, cfg)
// after
cfg := &yugabytedb.Config{DatabaseName: os.Getenv("YUGABYTE_DB")}
if cfg.DatabaseName == "" {
return nil, errors.New("YUGABYTE_DB must be set")
}
m, err := yugabytedb.WithInstance(session, cfg) Defensive patterns
Strategy: validation
Validate before calling
if cfg == nil || cfg.DatabaseName == "" {
return nil, errors.New("yugabytedb: database name is required")
}
driver, err := yugabytedb.WithInstance(session, cfg) Type guard
func hasDatabaseName(cfg *yugabytedb.Config) bool {
return cfg != nil && len(cfg.DatabaseName) > 0
} Prevention
- Load DatabaseName from env/config at startup and fail fast if empty
- Include the database in the Open URL instead of relying on separate config
- Validate all required Config fields (DatabaseName, MigrationsTable) in one place before driver creation
When it happens
Trigger: Calling WithInstance/WithConnection/Open with a Config whose DatabaseName is ""; Open with a URL that lacks a database name component; WithInstance after detecting len(config.DatabaseName) == 0.
Common situations: Forgetting to set DatabaseName when constructing Config manually; parsing a connection URL that omits the database path; env-var-driven config where the DB_NAME variable is unset or empty after trimming.
Related errors
- no config
- max retries exceeded
- digits must be positive
- the seq and format options are mutually exclusive
- time format may not be empty
AI-assisted analysis of golang-migrate/migrate@01a9643f14 (2026-09-02).
Data as JSON: /api/errors/47e7b88ad4e4c8da.
Report an issue: GitHub.