Skip to content

Error: Sqlite primary key syntax error #361

Description

@fairking

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")
);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions