You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
GORM creates column without autoincrement:
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 erroris thrown when trying to create table with
because GORM tries
ID
as PK by default (because of col name) and adds PK also toIDH
(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.The text was updated successfully, but these errors were encountered: