golang-migrate/migrate · error
no database name
Error message
no database name
What it means
ErrNoDatabaseName is a sentinel error returned by the sqlite driver's WithInstance, Open, and WithConnection when Config.DatabaseName (or the URL path) is empty. The driver requires a database name to manage migration state. It indicates the migration URL or config is incomplete.
Source
Thrown at database/sqlite/sqlite.go:26
nurl "net/url"
"strconv"
"strings"
"sync/atomic"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database"
_ "modernc.org/sqlite"
)
func init() {
database.Register("sqlite", &Sqlite{})
}
var DefaultMigrationsTable = "schema_migrations"
var (
ErrDatabaseDirty = fmt.Errorf("database is dirty")
ErrNilConfig = fmt.Errorf("no config")
ErrNoDatabaseName = fmt.Errorf("no database name")
)
type Config struct {
MigrationsTable string
DatabaseName string
NoTxWrap bool
}
type Sqlite struct {
db *sql.DB
isLocked atomic.Bool
config *Config
}
func WithInstance(instance *sql.DB, config *Config) (database.Driver, error) {
if config == nil {
return nil, ErrNilConfigView on GitHub (pinned to 01a9643f14)
Solutions
- Set Config.DatabaseName or include the path in the URL (sqlite:///path/to/app.db) before constructing the driver.
- Validate the database name is non-empty in your config loading and fail fast with a clear message.
- Check the deployment environment actually provides the DB filename (env var/config value not empty).
Example fix
// before
cfg := &sqlite.Config{} // DatabaseName empty
d, err := sqlite.WithInstance(db, cfg) // ErrNoDatabaseName
// after
cfg := &sqlite.Config{
DatabaseName: "data/app.db",
}
d, err := sqlite.WithInstance(db, cfg) Defensive patterns
Strategy: validation
Validate before calling
if cfg == nil || strings.TrimSpace(cfg.DatabaseName) == "" {
return fmt.Errorf("sqlite requires a non-empty DatabaseName")
}
// or for URLs: ensure a path exists
u, _ := url.Parse(dsn)
if u.Path == "" { return fmt.Errorf("migration URL missing database path: %s", dsn) } Type guard
func hasDatabaseName(cfg *sqlite.Config) bool {
return cfg != nil && strings.TrimSpace(cfg.DatabaseName) != ""
} Try / catch
if err != nil {
if errors.Is(err, sqlite.ErrNoDatabaseName) {
return fmt.Errorf("check migration DSN/config: database name is required: %w", err)
}
return err
} Prevention
- Validate the DSN has a path component before handing it to migrate.
- Fail at startup if the env var holding the DB filename is empty.
- Keep DSN construction in one tested helper function.
When it happens
Trigger: Calling sqlite.Open("sqlite://") with no path, or WithInstance/WithConnection with a Config whose DatabaseName is "" — e.g. a programmatically built URL that lost its path component.
Common situations: DSN missing the file path after sqlite://; env var supplying the DB filename empty or unset; URL parsing/cleaning stripping the path; Config struct built without the DatabaseName field.
Related errors
AI-assisted analysis of golang-migrate/migrate@01a9643f14 (2026-09-02).
Data as JSON: /api/errors/9746a5e5b8329891.
Report an issue: GitHub.