go-gorm / playground

GORM Playground (Please Create PR for this project to report issues)
MIT License
88 stars 666 forks source link

sqlite: primary key contstraint gets lost when embedded struct also contains primary key #712

Open phil9909 opened 3 months ago

phil9909 commented 3 months ago

For the following model

type Common struct {
    TenantID uint `gorm:"primarykey"`
}

type User struct {
    Common
    UserID string `gorm:"primarykey"`
    // ...
}

this SQL DDL is generated

CREATE TABLE `users` (`tenant_id` integer PRIMARY KEY AUTOINCREMENT,`user_id` text, [...])

Notice: The user_id is missing the PRIMARY KEY constraint

It worked fine with gorm.io/driver/sqlite v1.5.3 but is broken in gorm.io/driver/sqlite v1.5.4