Search code examples
go-gorm

Gorm: How to set unsigned interger in tags


I have the following struct with which when I run AutoMigration I expect unsigned to be set on table field quantity quantity but it doesn't.

Here is the struct I use

type Item struct {
    ID           int        `json:"id" gorm:"primaryKey"`
    Quantity     int        `json:"quantity" gorm:"type:integer;not null;unsigned;"`

}

SQL generated without UNSIGNED

    "id" BIGINT NOT NULL DEFAULT 'nextval(''items_id_seq''::regclass)',
    "quantity" INTEGER NOT NULL,

How to make unsigned work with gorm and postgres? Any help will be appreciated.


Solution

  • `gorm:"type:decimal(16,2) unsigned;not null;"`
    

    don't put a semicolon between a data type and unsigned. Worked in mysql, postgres dont have type unsigned