golang-migrate/migrate · error
no database name
Error message
no database name
What it means
ErrNoDatabaseName in the sqlite3 migrate driver is returned by WithInstance, Open, or WithConnection when the resolved database name is empty. For sqlite3 this corresponds to the database file path (purl.Path) being blank, so migrations cannot be recorded.
Source
Thrown at database/sqlite3/sqlite3.go:26
nurl "net/url"
"strconv"
"strings"
"sync/atomic"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database"
_ "github.com/mattn/go-sqlite3"
)
func init() {
database.Register("sqlite3", &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
- Include the database file path in the URL: sqlite3://path/to/db.sqlite3
- Set config.DatabaseName when calling WithInstance/WithConnection
- Verify the env/flag that supplies the path is populated before opening
Example fix
// before
d, err := migrate.Open("sqlite3://")
// after
d, err := migrate.Open("sqlite3://data/app.db") Defensive patterns
Strategy: validation
Validate before calling
if dbPath == "" {
return errors.New("sqlite3 URL must include the database file path")
}
d, err := migrate.Open("sqlite3://" + dbPath) Type guard
func hasDatabaseName(path string) bool { return strings.TrimSpace(path) != "" } Prevention
- Validate the URL/path from env vars before calling Open
- Use os.Stat on the sqlite file when you expect an existing DB
- Log the fully assembled URL (redacting credentials) in startup diagnostics
When it happens
Trigger: Open-ing a URL like 'sqlite3://' or 'sqlite3://?x-no-tx-wrap=true' with no path, or WithInstance where config.DatabaseName was not set.
Common situations: Building the connection URL from env vars that are empty or unset; URL parsing dropping the path; forgetting the file name when switching from a DSN string to a parsed URL.
Related errors
AI-assisted analysis of golang-migrate/migrate@01a9643f14 (2026-09-02).
Data as JSON: /api/errors/6350670a0eb2ec2d.
Report an issue: GitHub.