0

I have the following scenario: My app published with database version 2 to the customers. I fixed some bugs and added more features in my DB. This also changed my models and that's why the database changed too. How to give migration scripts in Android studio, I saw suggestion for adding migration scripts for eclipse. But I didn't find any solution for android studio.

Detail Description

I followed the wiki instructions: https://github.com/pardom/ActiveAndroid/wiki/Schema-migrations and tried to add a column to a per-existing db table but that's not working.

My initialenter code here Model class

@Table(name = "Person")
public class Person extends Model 
{
@Column
private String name;
}

All fine. Then I added a new field called age:

@Table(name = "Person")
public class Person extends Model 
{
@Column
private String name;
@Column
private int age;
}

and changed the manifest flag + created the required assets/migrations/2.sql script

ALTER TABLE Person ADD COLUMN age INTEGER;

Where I have to provide this migration script in AndroidStudio environment. Any clues?

I also update the database version in Manifest file. Still i am getting following exception

android.database.sqlite.SQLiteException: no such table: Tablename (code 1): , while compiling: SELECT * FROM TableName
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:891)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:502)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1255)
at com.activeandroid.Model.rawQuery(Model.java:349)
at com.activeandroid.Model.rawQuerySingle(Model.java:369)
at com.activeandroid.query.From.executeSingle(From.java:159)
at com.eshopmanager.shopmanager10.MainActivity$1.run(MainActivity.java:127)
at java.util.Timer$TimerImpl.run(Timer.java:284) 
G Sri
  • 31
  • 3
  • What have you done in onUpgrade method? – Harin Jul 08 '15 at 07:16
  • I updated db version in manifest file. I wanna give migrate script. But do know where i have to place in source code of androidstudio . No assets file in the code just like in eclipse –  G Sri Jul 08 '15 at 09:17
  • Look here - http://stackoverflow.com/questions/17385466/how-to-update-table-with-activeandroid-after-adding-a-new-column – Anton Kizema Feb 19 '16 at 10:28

1 Answers1

2

I solved the issue by creating assets folder in main. After that i created migration. Placed sql file in that. So that my database changes effects.

G Sri
  • 31
  • 3