Skip to content

Autoincrement is not enabled in SQLite when used with AutoMigrate #4760

@iSLC

Description

@iSLC

Description

Very simple use case:

package main

import (
	"log"
	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
)

type User struct {
	ID   int64  `gorm:"primaryKey;autoIncrement;not null"`
	Name string `gorm:"unique;not null"`
	Mail string `gorm:"unique;not null"`
	Pass string `gorm:"unique;not null"`
}

func main() {
	con, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
	if err != nil {
		log.Panic(err)
	}
	con.AutoMigrate(User{})
}

The database and table is created. Everything else is fine. Except AUTOINCREMENT is not enabled on primary key. What am I doing wrong here? (I have not tried with other drivers) (just tried on mysql and works fine there)

This is the DDL of the generated table:

CREATE TABLE users (
    id   INTEGER NOT NULL,
    name TEXT    NOT NULL
                 UNIQUE,
    mail TEXT    NOT NULL
                 UNIQUE,
    pass TEXT    NOT NULL
                 UNIQUE,
    PRIMARY KEY (
        id
    )
);

OS: Windows x64
GO: 1.17.2 (fresh installation. just began learning go)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions