Unable to add column to table
Hi Team,
I have a table with below structure.
@Table(name="books") public class Books extends Model { @Column(name = "bookId") public String bookId; }
I want to Add a new column. I followed the steps mentioned in https://github.com/pardom/ActiveAndroid/wiki/Schema-migrations. But I am getting the below error:
Caused by: android.database.sqlite.SQLiteException: not an error (code 0)
This happens at My Application class where I am initializing active android.
Please Help.
Thanks.
Could we have the full stacktrace and the migration-script, please?
Hi,
Here is the stack trace.
java.lang.RuntimeException: Unable to create application com.hannan.delivery.MyApplication: android.database.sqlite.SQLiteException: not an error (code 0) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4154) at android.app.ActivityThread.access$1300(ActivityThread.java:130) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4745) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method) Caused by: android.database.sqlite.SQLiteException: not an error (code 0) at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method) at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:727) at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754) at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64) at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1665) at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594) at com.activeandroid.DatabaseHelper.executeSqlScript(DatabaseHelper.java:180) at com.activeandroid.DatabaseHelper.executeMigrations(DatabaseHelper.java:150) at com.activeandroid.DatabaseHelper.onUpgrade(DatabaseHelper.java:74) at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:257) at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164) at com.activeandroid.Cache.openDatabase(Cache.java:102) at com.activeandroid.Cache.initialize(Cache.java:75) at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:44) at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:34) at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:30) at com.activeandroid.app.Application.onCreate(Application.java:25) at com.hannan.delivery.MyApplication.onCreate(MyApplication.java:51) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:999) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4151) at android.app.ActivityThread.access$1300(ActivityThread.java:130) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4745) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method)
On Mon, Apr 28, 2014 at 5:54 PM, Niki Hansche [email protected]:
Could we have the full stacktrace and the migration-script, please?
— Reply to this email directly or view it on GitHubhttps://github.com/pardom/ActiveAndroid/issues/222#issuecomment-41551929 .
Migration Script: (3.sql) ALTER TABLE books ADD COLUMN bookAuthor TEXT;
Also Tried with ALTER TABLE books ADD bookAuthor TEXT;
Both are resulting in same error.
I could also see the below errors:
1553-1553/com.hannan.delivery E/SQLiteLog﹕ (21) API called with NULL prepared statement 1553-1553/com.hannan.delivery E/SQLiteLog﹕ (21) misuse at line 63241 of [00bb9c9ce4]
Please check and let me know what has to be done?
Hi HannanShaik!
I’m really sorry, but I couldn’t reproduce this error, which means the error is in your setup, not in ActiveAndroid.
If you want to, you can download http://uploaded.net/file/3zom6ayx
it is a git-bundle called aat. You can clone it with the command git clone /tmp/aat (if you saved it in /tmp). After that you can see what I did using git log -p.
Commit Version 1 is the initial project, Version 2 adds a new column.
I'm getting this as well. A fresh install works fine.
Although my scenario is a bit different. When I did my migration, a column would go missing in one of my tables. (I didn't remove it). Trying to add it manually with the migration script would result in this error.
Figured it out, I think. Would an empty line (blank space) cause an issue here? One migration script I had did and it failed. I removed it and it seemed to work.
I also had this issue - the reason is because comments, newlines, and queries broken up across multiple lines are not processed correctly - my guess is because the migration is being ran line-by-line, so multi-line queries fail and comments and spaces become nulls.
Please have a look at #215.
@vonloxley thanks for the heads up, using that tag fixes it for me!
@HannanShaik You can now close this issue :)