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 autoincrement columns are not created #669

Closed
ispbox opened this issue Oct 28, 2019 · 3 comments
Closed

SQLite autoincrement columns are not created #669

ispbox opened this issue Oct 28, 2019 · 3 comments

Comments

@ispbox
Copy link

ispbox commented Oct 28, 2019

I tried to create integer autoincremented column via Exposed DSL. In debug I see that SQLite dialect is properly selected, but both variants I tried doesn't work.

This definition:

object Users : Table("users") {
    val id = integer("id").primaryKey().autoIncrement()
}

gives:

SQL: CREATE TABLE IF NOT EXISTS users (id INTEGER AUTOINCREMENT NOT NULL, CONSTRAINT pk_users PRIMARY KEY (id))

org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (near "AUTOINCREMENT": syntax error)

The same is created without .primaryKey()

Correct SQL in this case should be:

CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY ASC)
or
CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT)

according to https://www.sqlite.org/autoinc.html.
Probably SQLiteDialect should be somehow updated?

@ispbox
Copy link
Author

ispbox commented Nov 2, 2019

Does anyone has the same problem?
My current workaround is direct SQL statements:

transaction {
           exec("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY ASC)")
           SchemaUtils.create(/*Other tables without autoincrement*/)
}

@ispbox
Copy link
Author

ispbox commented Nov 2, 2019

I found two other possible solutions.

  1. Reverse order:
integer("id").autoIncrement().primaryKey()

(just let autoincrement be before primary key). Not intuitive, but works.

  1. Use inheritance from IntIdTable that does the same trick:
object Users : IntIdTable("users")

@ispbox ispbox closed this as completed Nov 2, 2019
@Tapac
Copy link
Contributor

Tapac commented Nov 3, 2019

Fixed in master and will be available soon.

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