A migration can handle more than 1 version (e.g. if you have a faster path to choose when going version 3 to 5 without going to version 4). If Room opens a database at version 3 and latest version is < 5, Room will use the migration object that can migrate from 3 to 5 instead of 3 to 4 and 4 to 5.
If there are not enough migrations provided to move from the current version to the latest version, Room will clear the database and recreate so even if you have no changes between 2 versions, you should still provide a Migration object to the builder.
migrate cannot access any generated Dao in this method.
migrate is already called inside a transaction and that transaction might actually be a composite transaction of all necessary Migrations.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-07-16 UTC.
[null,null,["Last updated 2025-07-16 UTC."],[],[],null,["# androidx.room.migration\n=======================\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/androidx/room/migration/package-summary \"View this page in Java\")\nCommon/AllAndroid/JVMNative/C/iOS\n\nInterfaces\n----------\n\n|----------------------------------------------------------------------------------|---------------------------------------------------------------------------------|---------------|\n| [AutoMigrationSpec](/reference/kotlin/androidx/room/migration/AutoMigrationSpec) | Interface for defining an automatic migration specification for Room databases. | Cmn android N |\n\nClasses\n-------\n\n|------------------------------------------------------------------|--------------------------------------|---------------|\n| [Migration](/reference/kotlin/androidx/room/migration/Migration) | Base class for a database migration. | Cmn android N |\n\nTop-level functions summary\n---------------------------\n\n|------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|\n| [Migration](/reference/kotlin/androidx/room/migration/Migration) | [Migration](/reference/kotlin/androidx/room/migration/package-summary#Migration(kotlin.Int,kotlin.Int,kotlin.Function1))`(` ` startVersion: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` endVersion: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` migrate: (`[SupportSQLiteDatabase](/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase)`) `-\u003e` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) `)` Creates [Migration](/reference/kotlin/androidx/room/migration/Migration) from [startVersion](/reference/kotlin/androidx/room/migration/package-summary#Migration(kotlin.Int,kotlin.Int,kotlin.Function1)) to [endVersion](/reference/kotlin/androidx/room/migration/package-summary#Migration(kotlin.Int,kotlin.Int,kotlin.Function1)) that runs [migrate](/reference/kotlin/androidx/room/migration/package-summary#Migration(kotlin.Int,kotlin.Int,kotlin.Function1)) to perform the necessary migrations. | android |\n\nTop-level functions\n-------------------\n\n### Migration\n\nandroid \nArtifact: [androidx.room:room-runtime](/jetpack/androidx/releases/room) \n[View Source](https://cs.android.com/search?q=file:androidx/room/migration/Migration.android.kt+function:Migration) \nAdded in [2.7.0](/jetpack/androidx/releases/room#2.7.0) \n\n```\nfun Migration(\n startVersion: Int,\n endVersion: Int,\n migrate: (SupportSQLiteDatabase) -\u003e Unit\n): Migration\n```\n\nCreates [Migration](/reference/kotlin/androidx/room/migration/Migration) from [startVersion](/reference/kotlin/androidx/room/migration/package-summary#Migration(kotlin.Int,kotlin.Int,kotlin.Function1)) to [endVersion](/reference/kotlin/androidx/room/migration/package-summary#Migration(kotlin.Int,kotlin.Int,kotlin.Function1)) that runs [migrate](/reference/kotlin/androidx/room/migration/package-summary#Migration(kotlin.Int,kotlin.Int,kotlin.Function1)) to perform the necessary migrations.\n\nA migration can handle more than 1 version (e.g. if you have a faster path to choose when going version 3 to 5 without going to version 4). If Room opens a database at version 3 and latest version is \\\u003c 5, Room will use the migration object that can migrate from 3 to 5 instead of 3 to 4 and 4 to 5.\n\nIf there are not enough migrations provided to move from the current version to the latest version, Room will clear the database and recreate so even if you have no changes between 2 versions, you should still provide a Migration object to the builder.\n\n[migrate](/reference/kotlin/androidx/room/migration/package-summary#Migration(kotlin.Int,kotlin.Int,kotlin.Function1)) cannot access any generated Dao in this method.\n\n[migrate](/reference/kotlin/androidx/room/migration/package-summary#Migration(kotlin.Int,kotlin.Int,kotlin.Function1)) is already called inside a transaction and that transaction might actually be a composite transaction of all necessary `Migration`s."]]