Android Room: One database with multiple tables

You have few variants how to solve this problem:

  • Add tables back but increase the version of database;

    @Database(entities={Users.class, Passwords.class}, version = 2)

  • Clean the application settings and build the new database;

Just clean the application cache and try to recreate the database.


It's simple like adding one entity table. Just add another table name using ",". And another table will be added.

@Database(entities = [TableUser::class, TableRecord::class], version = 1)

abstract class MyDatabase : RoomDatabase() {
    abstract fun myDao(): MyDao
}

I think you got this all wrong, Room.databaseBuilder should only be called once to setup the database and in that database class, you will construct multiple tables. For example:

Room.databaseBuilder(this, MyRoomDb.class, "mymaindb")
                .allowMainThreadQueries()
                .build()

And your MyRoomDb should look like this

@Database(
        entities = {
            Users.class,
            Passwords.class
        },
        version = VERSION
)
public abstract class MyRoomDb extends RoomDatabase {
...
}