GORM Playground Link

gorm 版本: gorm.io/gorm v1.23.8 gorm.io/driver/sqlite v1.3.6

Description

type Project struct {
    Id            int       `json:"id" gorm:"column:id;autoIncrement"`
        Id            int       `json:"id" gorm:"column:id;primaryKey;autoIncrement"`
}

使用autoMigrate创建表,.schema table命令后primaryKey生效,autoIncrement未生效

CREATE TABLE `project` (`id` integer,`name` varchar(20) NOT NULL,`creator` text,`test_stage` text,`test_lead` text,`test_device` text,`status` integer,`simulate_count` integer,`created_at` datetime,PRIMARY KEY (`id`));

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: zhengm-hub

  1. autoIncrement is not required by default
  2. Do this if you need to set it go // Do not set the field to ID Idx uint32 `json:"idx" gorm:"autoIncrement;not null;cloumn:idx"`

    Refer to the following * GORM uses the field with the name ID as the table’s primary key by default.referenced document gorm doc * gorm source code #L168-L174