golang-migrate/migrate · error

no database name

Error message

no database name

What it means

ErrNoDatabaseName is a sentinel error returned by the sqlcipher driver's WithInstance, Open, and WithConnection when the Config.DatabaseName (or the URL path) is empty. The driver uses the database name to manage the migrations state and cannot operate without it. It indicates the migration URL or config is incomplete.

Source

Thrown at database/sqlcipher/sqlcipher.go:26

	nurl "net/url"
	"strconv"
	"strings"
	"sync/atomic"

	"github.com/golang-migrate/migrate/v4"
	"github.com/golang-migrate/migrate/v4/database"
	_ "github.com/mutecomm/go-sqlcipher/v4"
)

func init() {
	database.Register("sqlcipher", &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, ErrNilConfig

View on GitHub (pinned to 01a9643f14)

Solutions

  1. Set Config.DatabaseName (or ensure the URL includes a path: sqlcipher://path/to/db.sqlite) before constructing the driver.
  2. Validate the database name is non-empty in your own config loading code and fail fast with a clear message.
  3. Check the env var / config file that supplies the database name is actually populated in the deployment environment.

Example fix

// before
cfg := &sqlcipher.Config{}
d, err := sqlcipher.WithInstance(db, cfg) // ErrNoDatabaseName
// after
cfg := &sqlcipher.Config{
    DatabaseName: "data/app.db",
}
d, err := sqlcipher.WithInstance(db, cfg)
Defensive patterns

Strategy: validation

Validate before calling

if cfg == nil || strings.TrimSpace(cfg.DatabaseName) == "" {
    return fmt.Errorf("sqlcipher 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 *sqlcipher.Config) bool {
    return cfg != nil && strings.TrimSpace(cfg.DatabaseName) != ""
}

Try / catch

if err != nil {
    if errors.Is(err, sqlcipher.ErrNoDatabaseName) {
        return fmt.Errorf("check migration DSN/config: database name is required: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling sqlcipher.Open("sqlcipher://file.db") with no path component, or WithInstance/WithConnection with a Config whose DatabaseName is "" — e.g. building the URL programmatically and the path/database name got dropped.

Common situations: Hand-written connection URL missing the database path after sqlcipher://; env var holding the DB name empty or unset; URL parsers stripping the path; using a config struct with the DatabaseName field forgotten.

Related errors


AI-assisted analysis of golang-migrate/migrate@01a9643f14 (2026-09-02). Data as JSON: /api/errors/f6693dc1179a6b84. Report an issue: GitHub.