Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoMigrate has a duplicate column name problem. #29

Closed
tangyang9464 opened this issue Apr 21, 2022 · 6 comments
Closed

AutoMigrate has a duplicate column name problem. #29

tangyang9464 opened this issue Apr 21, 2022 · 6 comments

Comments

@tangyang9464
Copy link

go-gorm/sqlite has solved it. see go-gorm/sqlite

@glebarez
Copy link
Owner

glebarez commented Apr 21, 2022

I actually try very hard to keep this repo up-to-date.
The fix-commit for the issue you've mentioned was merged in this fork, see 55a60eb

Can you provide some code for reproducing the issue?

@tangyang9464
Copy link
Author

@glebarez
First you need to have a casbin.db file. Then run code.

type CasbinRule struct {
	ID    uint   `gorm:"primaryKey;autoIncrement"`
	Ptype string `gorm:"size:100"`
	V0    string `gorm:"size:100"`
	V1    string `gorm:"size:100"`
	V2    string `gorm:"size:100"`
	V3    string `gorm:"size:100"`
	V4    string `gorm:"size:100"`
	V5    string `gorm:"size:100"`
	V6    string `gorm:"size:25"`
	V7    string `gorm:"size:25"`
}

db, err:= gorm.Open(sqlite.Open("casbin.db"), &gorm.Config{})
// first create table
      if err= db.AutoMigrate(&CasbinRule{}); err!= nil {
            fmt.Print(err2)
}
// then modify tabel struct
      if err= db.Exec(fmt.Sprintf("CREATE UNIQUE INDEX %s ON %s (ptype,v0,v1,v2,v3,v4,v5,v6,v7)", "testIndex", "casbin_rule")).Error; err!= nil {
            fmt.Print(err2)
}
// create table again,then it will give an error
      if err= db.AutoMigrate(&CasbinRule{}); err!= nil {
            fmt.Print(err2)
}

I think this is the first case in AutoMigrate bug. First AutoMigrate create table, and then modify the table structure by modifying the index, last AutoMigrate will make an error again.

@tangyang9464
Copy link
Author

I actually try very hard to keep this repo up-to-date. The fix-commit for the issue you've mentioned was merged in this fork, see 55a60eb

Can you provide some code for reproducing the issue?

@glebarez sry, I was mistaken, this change has indeed been merged into this repository. But the bug still exists in this repo and the official repository go-gorm/sqlite.

@glebarez
Copy link
Owner

@tangyang9464 thanks for elaboration.
I created an issue go-gorm/gorm#5282 to the upstream.

@glebarez
Copy link
Owner

glebarez commented Apr 21, 2022

fixed this issue f7607bf
PR to upstream filed go-gorm#90

@tangyang9464
Copy link
Author

fixed this issue f7607bf PR to upstream filed go-gorm#90

It works. closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants