Reputation: 199
I'm frustated. I'm looking for a solution over few hours....
I've got a simple room database:
@Database(entities = {User.class, Driver.class}, version = 1, exportSchema = true)
public abstract class AppDatabase extends RoomDatabase {
private static AppDatabase instance;
static AppDatabase getDatabase(Context context) {
if (instance == null) {
instance = Room.databaseBuilder(context, AppDatabase.class, "mytest.db").createFromAsset("databases/mytest.db") .build();
}
return instance;
}
public abstract UserDao userDao();
}
And:
@Entity(tableName = "Driver",
indices = {@Index(value = {"driverName"},unique = true), @Index(value = {"drivingLicNum"},unique = true)}
)
public class Driver {
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
@NotNull
private int id;
@ColumnInfo(name = "firstName")
@NotNull
private String firstName;
@ColumnInfo(name = "lastName")
@NotNull
private String lastName;
@ColumnInfo(name = "driverName")
@NotNull
private String driverName;
//optionale Parameter
@ColumnInfo(name = "birthDate")
@TypeConverters(Converters.class)
private Date birthDate;
@ColumnInfo(name = "drivingLicNum")
private String drivingLicNum;
@ColumnInfo(name = "drivingLicExpDate")
@TypeConverters(Converters.class)
private Date drivingLicExpDate;
@ColumnInfo(name = "gender")
@TypeConverters(Converters.class)
private Gender gender;
@ColumnInfo(name = "issuingAuthority")
private String issuingAuthority;
@ColumnInfo(name = "licCategory")
@TypeConverters(Converters.class)
private ArrayList<LicenceCategory> licCategory;
@ColumnInfo(name = "isActive", defaultValue = "1")
@NotNull
private boolean isActive;
@ColumnInfo(name = "profilePic")
private byte[] profilePic;
public Driver(@NotNull String firstName, @NotNull String lastName, @NotNull String driverName) {
this.firstName = firstName;
this.lastName = lastName;
this.driverName = driverName;
licCategory = new ArrayList<>();
setIsActive(true);
}
}
And:
@Entity
public class User {
@PrimaryKey(autoGenerate = true)
@ColumnInfo( name="uid")
@NotNull
public int uid;
@ColumnInfo(name = "first_name")
public String firstName;
@ColumnInfo(name = "last_name")
public String lastName;
public User( String firstName, String lastName){//,//int field4){
this.firstName = firstName;
this.lastName = lastName;
}
}
When I try creating/loading the database I always receive the error mentioned above. Things I already tried:
version=1 to version=2
exportSchema
to false
fallbackToDestructiveMigration()
None of the solutions solved my problem, I'm getting desperate. Am I missing some important step?
Upvotes: 2
Views: 243
Reputation: 56948
I believe that your issue is that you are importing the database from the assets and that the version number has been set to 1 in the imported database.
That is first Room is detecting that it cannot verify the data integrity because there the room_master_table table doesn't exist in the imported database.
Then Room finds that the database has a version number of 1 (as is stored in the header of the database file) and hence it saying that the version number has been changed. This being the real issue rather than the unable to verify the data integrity.
I believe that you need to change the version number to 0 in the database being imported. That is open it in DBBeaver, click on the Edit Pragmas and change the version number from 1 to 0. e.g. :-
Upvotes: 1