golang-migrate/migrate · error

no config

Error message

no config

What it means

ErrNilConfig is the redshift driver's sentinel returned by WithInstance and WithConnection when the supplied *Config is nil. Redshift is protocol-compatible with postgres and mirrors its driver structure, so it needs a non-nil config to read the migrations table and database name settings.

Source

Thrown at database/redshift/redshift.go:29

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

	"github.com/golang-migrate/migrate/v4"
	"github.com/golang-migrate/migrate/v4/database"
	"github.com/lib/pq"
)

func init() {
	db := Redshift{}
	database.Register("redshift", &db)
}

var DefaultMigrationsTable = "schema_migrations"

var (
	ErrNilConfig      = fmt.Errorf("no config")
	ErrNoDatabaseName = fmt.Errorf("no database name")
)

type Config struct {
	MigrationsTable string
	DatabaseName    string
}

type Redshift struct {
	isLocked atomic.Bool
	conn     *sql.Conn
	db       *sql.DB

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

func WithInstance(instance *sql.DB, config *Config) (database.Driver, error) {

View on GitHub (pinned to 01a9643f14)

Solutions

  1. Pass a non-nil &redshift.Config{DatabaseName: ..., MigrationsTable: redshift.DefaultMigrationsTable}
  2. Use the Open(dsn) entry point so the config is derived from the URL automatically
  3. Guard call sites with a nil check on config before invoking WithInstance

Example fix

// before
d, err := redshift.WithInstance(instance, nil)
// after
d, err := redshift.WithInstance(instance, &redshift.Config{
    DatabaseName:    "analytics",
    MigrationsTable: redshift.DefaultMigrationsTable,
})
Defensive patterns

Strategy: validation

Validate before calling

func validateRedshiftConfig(cfg *redshift.Config) error {
    if cfg == nil {
        return errors.New("redshift config must not be nil")
    }
    if cfg.MigrationsTable == "" {
        cfg.MigrationsTable = redshift.DefaultMigrationsTable
    }
    return nil
}

Type guard

func hasConfig(cfg *redshift.Config) bool { return cfg != nil }

Prevention

When it happens

Trigger: Calling redshift.WithInstance(instance, nil) or redshift.WithConnection(conn, nil).

Common situations: Programmatic driver construction embedded in another tool; copying postgres driver examples where the config was built elsewhere and passing nil as a placeholder.

Related errors


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