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

AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY #288

Closed
pplant opened this issue Jun 21, 2015 · 2 comments
Closed

AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY #288

pplant opened this issue Jun 21, 2015 · 2 comments
Labels
Milestone

Comments

@pplant
Copy link
Contributor

pplant commented Jun 21, 2015

Hi,

(using version 2.1.0)

whenever I add a @PrimaryKey(autoincrement = true) to a model I got the following exception

java.lang.RuntimeException: Unable to create application com.zlagup.app.ZlagUpApplication: android.database.sqlite.SQLiteException: AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY (code 1): , while compiling: CREATE TABLE IF NOT EXISTS set_stats(id INTEGER(0) PRIMARY KEY AUTOINCREMENT, completed INTEGER(0), set_id INTEGER, stats_id INTEGER, FOREIGN KEY(set_id) REFERENCES set (id) ON UPDATE CASCADE ON DELETE CASCADE , FOREIGN KEY(stats_id) REFERENCES stats (id) ON UPDATE CASCADE ON DELETE CASCADE );
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4521)
at android.app.ActivityThread.access$1500(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Tried to change the datatype of the field from long to int but without success (Cleaning and reinstalling app didn't solved the problem). Did you experience such a problem in the past. I looked through the old issues but couldn't find something similar.

Update: Tried to investigate a bit on this issue and saw that removing the column length "(0)" after the data type within the create statement seems to solve the problem. Found this in the official SQLite docs:

"Note that numeric arguments in parentheses that following the type name (ex: "VARCHAR(255)") are ignored by SQLite - SQLite does not impose any length restrictions (other than the large global SQLITE_MAX_LENGTH limit) on the length of strings, BLOBs or numeric values."

@agrosner
Copy link
Owner

agrosner commented Jul 2, 2015

@pplant saw your PR, if you could reopen it against develop, this issue will be solved.

@agrosner agrosner added the bug label Jul 2, 2015
@agrosner agrosner added this to the 2.2.1 milestone Jul 2, 2015
@pplant
Copy link
Contributor Author

pplant commented Jul 2, 2015

Ok reopened it against develop branch

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

No branches or pull requests

2 participants