Search code examples
androidandroid-room

Room Auto Migration showing compile time error


I am using Room 2.4.0-alpha01

but it show me this error

Schemas required for migration are not found at path: \app\schemascom.pigeon.mangaer.AppDB/2.json. Cannot generate auto migrations.

here is my code:

@Database(
    exportSchema = true,
    version = 3,
    entities = [Pigeon::class,PairEntity::class],
    autoMigrations = [
        AutoMigration(from = 2,to = 3)
                     ]
   )
abstract class AppDB:RoomDatabase() {
    abstract  fun  pigeonDao():PigeonDao
    abstract fun  pairDao():PairDao
}

Solution

  • Room Auto-migration requires you to export your database schema, so it can know how your database was in the previous version, in order to generate the auto-migration. This was stated at a post on Medium by Florina Muntenescu:

    ⚠️Note: Under the hood, Room auto-migrations rely on the generated database schema, so make sure that the exportSchema option in @Database is true while using autoMigrations. Otherwise it leads to an error: Cannot create auto-migrations when export schema is OFF.

    This answer shows how to add the option exportSchema correctly to your project.