golang-migrate/migrate · error
no database name
Error message
no database name
What it means
spanner.ErrNoDatabaseName is returned when the Spanner driver cannot determine the target database. WithInstance/WithConnection return it when Config.DatabaseName is empty, and Open returns it when the spanner:// URL lacks the database path. Spanner migrations are scoped to a specific database, so it is mandatory.
Source
Thrown at database/spanner/spanner.go:37
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database"
adminpb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
"google.golang.org/api/iterator"
)
func init() {
db := Spanner{}
database.Register("spanner", &db)
}
// DefaultMigrationsTable is used if no custom table is specified
const DefaultMigrationsTable = "SchemaMigrations"
// Driver errors
var (
ErrNilConfig = errors.New("no config")
ErrNoDatabaseName = errors.New("no database name")
ErrNoSchema = errors.New("no schema")
ErrDatabaseDirty = errors.New("database is dirty")
ErrLockHeld = errors.New("unable to obtain lock")
ErrLockNotHeld = errors.New("unable to release already released lock")
)
// Config used for a Spanner instance
type Config struct {
MigrationsTable string
DatabaseName string
// Whether to parse the migration DDL with spansql before
// running them towards Spanner.
// Parsing outputs clean DDL statements such as reformatted
// and void of comments.
CleanStatements bool
}
// Spanner implements database.Driver for Google Cloud SpannerView on GitHub (pinned to 01a9643f14)
Solutions
- Provide the full database path in the URL: spanner://projects/myproj/instances/myinst/databases/mydb.
- Set Config.DatabaseName to the fully qualified 'projects/.../instances/.../databases/...' string when using WithInstance.
- Validate the database name/env var is non-empty before constructing the driver.
Example fix
// before
db, err := migrate.New("spanner://projects/p/instances/i", "file://migrations")
// after
db, err := migrate.New("spanner://projects/p/instances/i/databases/mydb", "file://migrations") Defensive patterns
Strategy: validation
Validate before calling
if cfg == nil || cfg.DatabaseName == "" {
return fmt.Errorf("spanner database name is required: projects/p/instances/i/databases/d")
} Type guard
func hasDatabaseName(cfg *spanner.Config) bool { return cfg != nil && cfg.DatabaseName != "" } Try / catch
if err := m.Up(); err != nil {
if errors.Is(err, spanner.ErrNoDatabaseName) {
return fmt.Errorf("check spanner:// URL, must end with /databases/<name>")
}
return err
} Prevention
- Store the fully qualified database path in one env var and validate it at startup.
- Check the URL has the /databases/<name> segment before calling migrate.New.
- Use the admin API or config validation to confirm the database exists.
When it happens
Trigger: WithInstance called with Config{DatabaseName: ""}; Open given a URL like 'spanner://projects/p/instances/i' with no '/databases/D' segment.
Common situations: Partially built spanner:// URLs missing the database component, empty env vars for the project/instance/database path, config assembled from flags where the database name was omitted.
Related errors
AI-assisted analysis of golang-migrate/migrate@01a9643f14 (2026-09-02).
Data as JSON: /api/errors/e1274d9c38c96820.
Report an issue: GitHub.