golang-migrate/migrate · error

no database name

Error message

no database name

What it means

ErrNoDatabaseName is returned by the ql driver when no database name was supplied — either Config.DatabaseName is empty in WithInstance/WithConnection, or the Open URL has no path. The driver needs the target database/schema name to place and address the migrations table.

Source

Thrown at database/ql/ql.go:25

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

	"github.com/golang-migrate/migrate/v4"
	"github.com/golang-migrate/migrate/v4/database"
	_ "modernc.org/ql/driver"
)

func init() {
	database.Register("ql", &Ql{})
}

var DefaultMigrationsTable = "schema_migrations"
var (
	ErrDatabaseDirty  = fmt.Errorf("database is dirty")
	ErrNilConfig      = fmt.Errorf("no config")
	ErrNoDatabaseName = fmt.Errorf("no database name")
	ErrAppendPEM      = fmt.Errorf("failed to append PEM")
)

type Config struct {
	MigrationsTable string
	DatabaseName    string
}

type Ql 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 to the target database name before calling WithInstance/WithConnection
  2. Include the database name in the URL path when using Open, e.g. ql://mydb
  3. Add startup validation that fails fast with a clear message if the configured database name is empty

Example fix

// before
cfg := &ql.Config{}
driver, err := ql.WithInstance(instance, cfg)
// after
cfg := &ql.Config{DatabaseName: os.Getenv("DB_NAME")}
if cfg.DatabaseName == "" {
    return errors.New("DB_NAME must be set")
}
driver, err := ql.WithInstance(instance, cfg)
Defensive patterns

Strategy: validation

Validate before calling

func requireDatabaseName(cfg *ql.Config) error {
    if cfg == nil || cfg.DatabaseName == "" {
        return errors.New("ql: DatabaseName is required")
    }
    return nil
}

Type guard

func hasDatabaseName(cfg *ql.Config) bool {
    return cfg != nil && cfg.DatabaseName != ""
}

Prevention

When it happens

Trigger: Calling ql.Open("ql://") with an empty path; WithInstance/WithConnection with a Config whose DatabaseName field is "".

Common situations: Building the config programmatically and forgetting to copy the database name from application settings; using a DSN generator that omits the path for the ql scheme.

Related errors


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