-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Comments
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! |
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
|
Fixed my problem by installing with go toolchain instead of Homebrew |
The proposed solution: |
The solution proposed by @wayjack worked for me, but on Windows make sure you have
|
The tool does not support SQLite out of the box: golang-migrate/migrate#670 #98
Proposal in #1085 to split this problem into two :) The linter is failing on CI for some weird reason, but that may be off-topic on this thread. |
If CGO is an issue, there are pure go SQLite driver implementations. Are they bad? |
Describe the Bug
run
migrate -path db/migrations -database sqlite3://db/dev.db version
but printerror: 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
The text was updated successfully, but these errors were encountered: