golang-migrate/migrate · error

no schema

Error message

no schema

What it means

Sentinel error ErrNoSchema defined in database/sqlserver/sqlserver.go. It is a generic guard indicating that no schema name was provided or resolvable when opening the driver. The same sentinel pattern exists in drivers like pgx, where Open returns it when the parsed schema name (e.g. the x-migrations-table schema component) is empty. Fix by specifying the schema in the connection URL or configuration.

Source

Thrown at database/sqlserver/sqlserver.go:30

	"sync/atomic"

	"github.com/Azure/go-autorest/autorest/adal"
	"github.com/golang-migrate/migrate/v4"
	"github.com/golang-migrate/migrate/v4/database"
	mssql "github.com/microsoft/go-mssqldb" // mssql support
)

func init() {
	database.Register("sqlserver", &SQLServer{})
}

// DefaultMigrationsTable is the name of the migrations table in the database
var DefaultMigrationsTable = "schema_migrations"

var (
	ErrNilConfig                 = fmt.Errorf("no config")
	ErrNoDatabaseName            = fmt.Errorf("no database name")
	ErrNoSchema                  = fmt.Errorf("no schema")
	ErrDatabaseDirty             = fmt.Errorf("database is dirty")
	ErrMultipleAuthOptionsPassed = fmt.Errorf("both password and useMsi=true were passed")
)

var lockErrorMap = map[int]string{
	-1:   "The lock request timed out.",
	-2:   "The lock request was canceled.",
	-3:   "The lock request was chosen as a deadlock victim.",
	-999: "Parameter validation or other call error.",
}

// Config for database
type Config struct {
	MigrationsTable string
	DatabaseName    string
	SchemaName      string
}

View on GitHub (pinned to 01a9643f14)

Solutions

  1. Append &schema=<name> to the sqlserver:// URL
  2. Set Config.SchemaName explicitly in WithInstance/WithConnection
  3. If the default dbo schema is intended, confirm your SQL Server user resolves to dbo rather than passing an empty schema

Example fix

// before
d, err := migrate.Open("sqlserver://sa:pass@localhost:1433?database=mydb")
// after
d, err := migrate.Open("sqlserver://sa:pass@localhost:1433?database=mydb&schema=dbo")
Defensive patterns

Strategy: validation

Validate before calling

u, _ := url.Parse(dsn)
if u.Query().Get("schema") == "" {
    return errors.New("sqlserver DSN must include schema=<name>")
}

Type guard

func hasSchema(u *url.URL) bool { return u.Query().Get("schema") != "" }

Prevention

When it happens

Trigger: Open with a URL lacking ?schema= while Config.SchemaName is empty; WithInstance/WithConnection with a Config that has no SchemaName and no schema resolvable from the URL.

Common situations: Migrating a schema other than dbo without specifying it; URLs copied from other drivers (mysql/pgx variants) that don't carry a schema parameter; team conventions requiring custom schemas.

Related errors


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