golang-migrate/migrate · error

no keyspace provided

Error message

no keyspace provided

What it means

ErrNoKeyspace is returned when the Cassandra driver cannot determine which keyspace to run migrations in. WithInstance returns it when config.KeyspaceName is empty; Open returns it when the cassandra:// URL has no keyspace in its path. The migrations table must live inside a keyspace, so the driver refuses to proceed.

Source

Thrown at database/cassandra/cassandra.go:33

	"github.com/golang-migrate/migrate/v4/database/multistmt"
)

func init() {
	db := new(Cassandra)
	database.Register("cassandra", db)
}

var (
	multiStmtDelimiter = []byte(";")

	DefaultMultiStatementMaxSize = 10 * 1 << 20 // 10 MB
)

var DefaultMigrationsTable = "schema_migrations"

var (
	ErrNilConfig     = errors.New("no config")
	ErrNoKeyspace    = errors.New("no keyspace provided")
	ErrDatabaseDirty = errors.New("database is dirty")
	ErrClosedSession = errors.New("session is closed")
)

type Config struct {
	MigrationsTable       string
	KeyspaceName          string
	MultiStatementEnabled bool
	MultiStatementMaxSize int
}

type Cassandra struct {
	session  *gocql.Session
	isLocked atomic.Bool

	// Open and WithInstance need to guarantee that config is never nil
	config *Config
}

View on GitHub (pinned to 01a9643f14)

Solutions

  1. Append the keyspace to the URL: cassandra://127.0.0.1:9042/mykeyspace.
  2. Set KeyspaceName in the *cassandra.Config when using WithInstance.
  3. Verify the config value is loaded from your env/config file before calling the driver (non-empty check).

Example fix

// before
db, err := migrate.New("cassandra://127.0.0.1:9042", "file://migrations")
// after
db, err := migrate.New("cassandra://127.0.0.1:9042/my_keyspace", "file://migrations")
Defensive patterns

Strategy: validation

Validate before calling

if cfg == nil || cfg.KeyspaceName == "" {
    return fmt.Errorf("cassandra keyspace is required")
}
u, err := url.Parse(dsn)
if err != nil || u.Path == "" {
    return fmt.Errorf("cassandra DSN must include /keyspace")
}

Try / catch

m, err := migrate.New(dsn, "file://migrations")
if errors.Is(err, cassandra.ErrNoKeyspace) {
    return fmt.Errorf("check DSN: expected cassandra://host:9042/keyspace")
}

Prevention

When it happens

Trigger: WithInstance called with Config{KeyspaceName: ""}; Open called with a URL like 'cassandra://host:9042/' (empty path) or a URL missing the keyspace path segment entirely.

Common situations: Hand-writing a DSN and forgetting the trailing '/keyspace' segment, env-var templating that left the keyspace blank, or building Config from flags where the keyspace flag was not provided.

Related errors


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