Reputation: 11
I am trying to add autoincrement to my table in a Go project but it doesn't seem to be working for me
`gorm:"primary_key;column:uuid;not_null;type:int(32);autoIncrement" json:"uuid"`
keeping this in the struct of the given field. (Also tried AUTO_INCREMENT, autoincrement but not working)
Upvotes: 0
Views: 1954
Reputation: 7762
In the documentation of the model field tags, it says (emphasis mine):
type: column data type, prefer to use compatible general type, e.g: bool, int, uint, float, string, time, bytes, which works for all databases, and can be used with other tags together, like not null, size, autoIncrement… specified database data type like varbinary(8) also supported, when using specified database data type, it needs to be a full database data type, for example: MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT
That means that if you use a specific datatype like int(32)
as you have done, you need to specify the full type string:
`gorm:"primary_key;column:uuid;type:int(32) NOT NULL AUTO_INCREMENT" json:"uuid"`
Upvotes: 2