Thomas Fischer
Thomas Fischer

Reputation: 1514

How to disable Android Room from managing the schema?

I'm new to Android Room. I would like to use it to read and write to my Sqlite database. I do NOT want it to manage the schema (create/migrate tables).

First, I'm not completely sold on Android Room yet, so I don't want to commit to it by having it manage my schema.

Second, I prefer complete control over the schema.

I currently get a Room exception when starting the app. I assume this is because Android Room encounters my existing schema.

java.lang.IllegalStateException: Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by increasing the version number.

How do I stop Android Room from creating/migrating tables?

Upvotes: 4

Views: 2676

Answers (2)

Moncef AOUDIA
Moncef AOUDIA

Reputation: 687

I think that you would like to stop auto generating database schema:

@Database(entities = {Person.class, Product.class}, version = 2, exportSchema = false)

exportSchema will disable auto generating schema by default.

Upvotes: 0

Misha Akopov
Misha Akopov

Reputation: 13057

If you change the database schema, e.g. either entity or something else, you have to increase version here:

 @Database(entities = {Person.class, Product.class}, version = 2)

That's it.

On the other hand if this issue bothers you in development mode, just uninstall/install app, and the error will disappear. Or just clear app's application data from settings.

In other cases you have to manage migrations.

Hope that helps.

Upvotes: 1

Related Questions