Description

I'm using sqlite and gorm isn't creating the proper length or uniqueness constraints for my models. (I didn't test any other backends because I'm not using those)

I've created a small test case that demonstrates this behavior:

package main

import (
    "fmt"
    "gorm.io/driver/sqlite"
    "gorm.io/gorm"
    "gorm.io/gorm/logger"
)

type Entry struct {
    ID        uint    `gorm:"primaryKey"`
    NameShort string  `gorm:"size:64,uniqueIndex"`
    NameLong  string  `gorm:"size:255"`
    Source    *string `gorm:"size:255"`
}

func (Entry) TableName() string {
    return "entries"
}

func main() {
    dbConfig := gorm.Config{
        Logger:      logger.Default.LogMode(logger.Info),
        PrepareStmt: true,
    }

    db, err := gorm.Open(sqlite.Open("test.db"), &dbConfig)
    if err != nil {
        panic("failed to connect database")
    }

    err = db.AutoMigrate(&Entry{})
    if err != nil {
        panic(fmt.Sprintf("AutoMigrate failed: %v", err))
    }

    exampleSource := "https://example.com"
    entry := Entry{
        NameShort: "This is a sentence that is a little longer than 64 characters and shouldn't fit.",
        NameLong:  "Entry 1",
        Source:    &exampleSource,
    }
    db.Create(&entry)
}

Run this and then inspect the resulting test.db file. This is what SQLiteStudio shows for me:

Screen Shot 2022-07-29 at 20 07 00

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: SamusAranX

It'd be great if this crummy bot would stop auto-marking every single issue as "stale". The test case is literally right there. I'm not constructing a dockerized whatever for an obvious bug that takes 5 seconds to verify using the code I posted.

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: a631807682

- NameShort string  `gorm:"size:64,uniqueIndex"`
+ NameShort string  `gorm:"size:64;uniqueIndex"`