-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Autoincrement is not enabled in SQLite when used with AutoMigrate #4760
Comments
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 2 days if no further activity occurs. if you are asking question, please use the |
@iSLC hello, a field declared as INTEGER PRIMARY KEY will automatically add in sqite doc look here and it explain this issue. |
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 2 days if no further activity occurs. if you are asking question, please use the |
@longlihale case schema.Int, schema.Uint:
if field.AutoIncrement && !field.PrimaryKey {
// https://www.sqlite.org/autoinc.html
return "integer PRIMARY KEY AUTOINCREMENT"
} else {
return "integer"
} I'll have to look more into it when I get home. Thanks for the reply. |
OK |
If you want to set the auto-increment on the ID field, using the |
The above is from the SQLite docs. I think, given the docs, the logic in |
Actually, one can use |
How was it finally resolved? |
Description
Very simple use case:
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:
OS: Windows x64
GO: 1.17.2 (fresh installation. just began learning go)
The text was updated successfully, but these errors were encountered: