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

Error: Sqlite primary key syntax error #361

Open
fairking opened this issue Feb 1, 2024 · 0 comments
Open

Error: Sqlite primary key syntax error #361

fairking opened this issue Feb 1, 2024 · 0 comments

Comments

@fairking
Copy link

fairking commented Feb 1, 2024

Packages:
github.com/go-rel/rel@v0.41.0
github.com/go-rel/migration@v0.3.1
github.com/go-rel/sqlite3@v0.11.0
github.com/mattn/go-sqlite3@v1.14.19

Example:

	schema.CreateTable("settings", func(t *rel.Table) {
		t.String("id", rel.Required(true), rel.Limit(16))
		t.String("key", rel.Required(true), rel.Limit(50))
		t.String("value")
		t.DateTime("created_at", rel.Required(true))
		t.DateTime("updated_at", rel.Required(true))

		t.PrimaryKey("id", rel.Name("pk_settings"))
		t.Unique([]string{"key"}, rel.Name("uq_settings_key"))
	})

Error:

Instrumentation: adapter-exec, INSERT INTO "rel_schema_versions" ("version","created_at","updated_at") VALUES (?,?,?);, [[202402011000 2024-02-01 02:23:55 +0100 CET 2024-02-01 02:23:55 +0100 CET]]
Instrumentation: adapter-exec, CREATE TABLE "settings" ("id" VARCHAR(16) NOT NULL, "key" VARCHAR(50) NOT NULL, "value" VARCHAR(255), "created_at" DATETIME NOT NULL, "updated_at" DATETIME NOT NULL, PRIMARY KEY "pk_settings" ("id"), UNIQUE "uq_settings_key" ("key"));, [[]]
Instrumentation: adapter-rollback, rollback transaction, [[]]
panic: near ""pk_settings"": syntax error

goroutine 56 [running]:
github.com/go-rel/migration.check({0x7ff7489cd3a0, 0xc000091830})
        /go/pkg/mod/github.com/go-rel/migration@v0.3.1/migration.go:176 +0x5d
github.com/go-rel/migration.(*Migration).Migrate(0xc00005c140, {0x7ff7489d1b98, 0xc000437fb0})
        /go/pkg/mod/github.com/go-rel/migration@v0.3.1/migration.go:127 +0x30e

The right syntax would be:

CREATE TABLE "settings" (
	"id"	VARCHAR(16) NOT NULL,
        "key" VARCHAR(50) NOT NULL,
	CONSTRAINT "pk_settings" PRIMARY KEY ("id"),
        CONSTRAINT "uq_settings_key" UNIQUE ("key")
);
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

1 participant