Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unknown driver sqlite3 #670

Open
bastengao opened this issue Dec 13, 2021 · 6 comments
Open

unknown driver sqlite3 #670

bastengao opened this issue Dec 13, 2021 · 6 comments

Comments

@bastengao
Copy link

Describe the Bug

run migrate -path db/migrations -database sqlite3://db/dev.db version but print error: database driver: unknown driver sqlite3 (forgotten import?).

Steps to Reproduce

Expected Behavior

Include sqlite3 driver default.

Migrate Version

v4.15.1

Loaded Source Drivers

Source drivers: godoc-vfs, file, s3, bitbucket, github-ee, gitlab, go-bindata, github, gcs

Loaded Database Drivers

Database drivers: mysql, neo4j, postgres, spanner, cassandra, postgresql, sqlserver, stub, cockroach, cockroachdb, crdb-postgres, firebirdsql, mongodb, pgx, redshift, clickhouse, mongodb+srv, firebird

Go Version

go version go1.17.5 darwin/arm64

Stacktrace

Additional context

@dhui
Copy link
Member

dhui commented Dec 18, 2021

This isn't possible to do today since we need to cross compile for different OSes and Arches. There are issues with doing this for the sqlite3 (github.com/mattn/go-sqlite3) db driver and the sqlite (modernc.org/sqlite) db driver. Feel free to try getting this to work and please open a PR if you're successful!

@dan-lovelace
Copy link

dan-lovelace commented Jan 15, 2022

I just fought with sqlite3 migrations for several hours and thought I'd share my solution here in case it helps others. This will run an UP migration, you'll just need to slightly modify for DOWN.

// db/migrate_up.go
package main

import (
	"database/sql"
	"log"

	"github.com/golang-migrate/migrate/v4"
	"github.com/golang-migrate/migrate/v4/database/sqlite3"
	"github.com/golang-migrate/migrate/v4/source/file"
)

func main() {
	db, err := sql.Open("sqlite3", "./test.db")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	instance, err := sqlite3.WithInstance(db, &sqlite3.Config{})
	if err != nil {
		log.Fatal(err)
	}

	fSrc, err := (&file.File{}).Open("./db/migrations")
	if err != nil {
		log.Fatal(err)
	}

	m, err := migrate.NewWithInstance("file", fSrc, "sqlite3", instance)
	if err != nil {
		log.Fatal(err)
	}

	// modify for Down
	if err := m.Up(); err != nil {
		log.Fatal(err)
	}
}

My folder structure

├── db
│   ├── migrations
│   │   ├── migration.down.sql
│   │   └── migration.up.sql
│   └── migrate_up.go
└── test.db

@xaqbr
Copy link

xaqbr commented May 4, 2022

Fixed my problem by installing with go toolchain instead of Homebrew
go install -tags 'sqlite3' github.com/golang-migrate/migrate/v4/cmd/migrate@latest

@mrthankyou
Copy link

mrthankyou commented Dec 5, 2022

The proposed solution: go install -tags 'mysql' github.com/golang-migrate/migrate/v4/cmd/migrate@latest does not work for me if I'm using mysql and docker. This is a pretty frustrating issue and I'm not sure why this error is occurring on the most basic of setups.

@Oxyrus
Copy link

Oxyrus commented Aug 10, 2023

The solution proposed by @wayjack worked for me, but on Windows make sure you have CGO_ENABLED=1 and of course mingw installed. You can do it in the following order (if you are using powershell)

  1. choco install mingw -y
  2. $env:CGO_ENABLED=1
  3. go install -tags 'sqlite3' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
  4. migrate -database sqlite3://yourdatabase.db -path db/migrations up

egorsmkv added a commit to egorsmkv/laravel-boilerplate that referenced this issue Apr 30, 2024
The tool does not support SQLite out of the box: golang-migrate/migrate#670

#98
@miklosbagi
Copy link

Proposal in #1085 to split this problem into two :)
It seems that the docker build is not multi-architecture, so likely there's no harm enabling CGO and the test DBs with that. 🍻

The linter is failing on CI for some weird reason, but that may be off-topic on this thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants