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

SQLite doesn't create sqlite_sequence table #67

Closed
laeo opened this issue Nov 30, 2021 · 2 comments
Closed

SQLite doesn't create sqlite_sequence table #67

laeo opened this issue Nov 30, 2021 · 2 comments
Assignees

Comments

@laeo
Copy link

laeo commented Nov 30, 2021

Description

Sample code below

type Message struct {
   ID int
}

I need set the initial auto increment value of message's id, and the sqlite's doc described the sqlite_sequence table. But when i try to manipulate it, i got an error, the table doesnt exists.

So i read the migrator's code, the DataTypeOf() method checks if the field is auto increment and not primary key field, migrator will generate proper statement to support auto increment.

But the ID field defaults handled as primary key, the problem seems can't fixed.

Gorm docs Conventions section say, we can use tag primaryKey to set other field as primary key, but migrator reports an error table device has more than one primary key.

How to fix it? Thanks for reply.

@jinzhu
Copy link
Member

jinzhu commented Oct 9, 2022

I don't get the question, can you please write a reproducible PR on gorm-go/gorm

Thank you.

@jinzhu jinzhu closed this as completed Oct 9, 2022
@orsinium
Copy link

orsinium commented Feb 4, 2023

From the SQLite docs:

In fact, it is created when the first table with an autoincrement column is created.

The sqlite_sequence table is not created unless you already have a table with an autoincrement field.

samuelncui pushed a commit to samuelncui/gorm-sqlite that referenced this issue Oct 4, 2023
…hub.com/glebarez/go-sqlite-1.19.2

Bump github.com/glebarez/go-sqlite from 1.19.1 to 1.19.2
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

3 participants