Skip to content

autoIncrement ignored when combined with primaryKey #134

Open
@pboguslawski

Description

@pboguslawski

Description

According to
https://www.sqlitetutorial.net/sqlite-autoincrement/
https://www.sqlite.org/autoinc.html
AUTOINCREMENT should be used in sqlite if one want's ID values not to be reused (i.e. after row deletion).

With table definition

ID uint64   `gorm:"column:id;not null;primaryKey;autoIncrement"`

GORM creates column without autoincrement:

CREATE TABLE `[...]` (`id` integer NOT NULL,[...],PRIMARY KEY (`id`));

but should add autoincrement also.

According to #126 one can create primary key + autoincrement with autoIncrement tag only but this looks like dirty hack and error

failed to create database schema: table "[...]" has more than one primary key

is thrown when trying to create table with

	IDH uint64 `gorm:"column:idh;not null;autoIncrement"` // Tried to create as PK+autoincrement.
	ID  uint64 `gorm:"column:id;not null"`                 // Tried to create as foreign key with ID name (makes sense in history table for us).

because GORM tries ID as PK by default (because of col name) and adds PK also to IDH (because of wrong handling of tags like above).

Expected behaviour

Column defined with gorm:"[...];primaryKey;autoIncrement" should be created as PK with autoincrement in sqlite db.

Metadata

Metadata

Assignees

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