2

I'm using ActiveAndroid and everything was working fine until I addded another ForeignKey to one model.

I have a model called Song which is like:

@Column(name = "author_id")
private String mAuthorId;

@Column(name = "created")
private long mCreated;

@Column(name = "album")
private Album mAlbum;

And another model Author which is:

@Column(name = "author_id")
private String mAuthorId;

@Column(name = "created")
private long mCreated;

private List<Album> mAlbums;

private List<Song> mSongs;

Everything was working fine but then I added a this new field to the Author's model: @Column(name = "last_song") private Song mLastSong;

Then, since I added the FK lastSong in the Author's model, after restarting the app I'm getting an error: E/CursorWindow﹕ Could not allocate CursorWindow '/data/data/package/databases/app.db' of size 2097152 due to error -12. I have about 7500 songs models and about 450 authors. What may be happening? Is there something wrong with my code?

Thanks in advance!

FVod
  • 2,245
  • 5
  • 25
  • 52

1 Answers1

0

You need to let ActiveAndroid and your app that you have updated the schema:

https://github.com/pardom/ActiveAndroid/wiki/Schema-migrations

Whenever your schema changes you need to increment the database version number, either through Configuration or AA_DB_VERSION meta-data. If new classes are added, ActiveAndroid will automatically add them to the database. If you want to change something in an existing table however (e.g. add or delete a column), this is done using sql-scripts named .sql, where NewVersion is the AA_DB_VERSION, in assets/migrations.

ActiveAndroid will execute a script if its filename is greater than the old database-version and smaller or equal to the new version.

Let’s assume you added a column color to the Items table. You now need to increase AA_DB_VERSION to 2 and provide a script 2.sql.

ALTER TABLE Items ADD COLUMN color INTEGER;

Community
  • 1
  • 1
Kaloyan Roussev
  • 14,515
  • 21
  • 98
  • 180
  • Hi, Thank you for your answer. I've deleted the application and installed again in order to avoid migration problems. The app opens fine, and all dataset is saved in database (about 7500 songs and 450 authors) without any error, but the next time I open the app the error is launched, so the app get about 2 or 3 minutes to open. What may be happening? Is this an out of memory error? – FVod Nov 10 '15 at 09:16
  • First of all, you can afford deleting and installing over inbetween schema changes, only if you haven't released a version to users yet. If there is already a version released to actual users, and you change the schema after the fact, you need to provide a backward compatibility mechanism, and you can't get away doing clean installs because you cannot force the users to do so. Keep that in mind. As for the 2-3 minutes delay, could be anything and it is not in the scope of this question. Insert Log calls in your activities' methods or debug the code and see where the bottleneck is. – Kaloyan Roussev Nov 10 '15 at 09:31
  • Hi, you are totally right, I haven't released any version yet, for this reason I'm deleting the app to avoid migration issues. While the app is opening (2/3 minutes) the log shows E/CursorWindow﹕ Could not allocate CursorWindow '/data/data/package/databases/app.db' of size 2097152 due to error -12 a lot of times, and without that new Foreign Key, the app open really quick without showing that error message. – FVod Nov 10 '15 at 09:45