Is it neccessary to add migration if new table is added in Room database?
up vote
0
down vote
favorite
I have two tables,person is already existing(added column userid as
foreign key)
@Entity(tableName = TABLE_NAME)
data class Person(
@PrimaryKey @ColumnInfo(name = CLIENT_ID) var id: Long,
@ColumnInfo(name = USER_ID)var userId : Int = 1) : Parcelable {}
this is the newly added class,which has foreign key of person
class(userid)
@Entity(tableName = Profile.TABLE_NAME,
foreignKeys = [ForeignKey(entity= Person::class,
parentColumns = [(Person.USER_ID)],
childColumns = [(Profile.USER_ID)],
onDelete = ForeignKey.CASCADE)])
@Parcelize
data class Profile(@PrimaryKey(autoGenerate = true)
var userId: Int,
var name: String? = null):Parcelable{}
Here i have two tables in the DB.
Now,do i need to write migration code for creation of new table?
New contributor
nithin krishna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
I have two tables,person is already existing(added column userid as
foreign key)
@Entity(tableName = TABLE_NAME)
data class Person(
@PrimaryKey @ColumnInfo(name = CLIENT_ID) var id: Long,
@ColumnInfo(name = USER_ID)var userId : Int = 1) : Parcelable {}
this is the newly added class,which has foreign key of person
class(userid)
@Entity(tableName = Profile.TABLE_NAME,
foreignKeys = [ForeignKey(entity= Person::class,
parentColumns = [(Person.USER_ID)],
childColumns = [(Profile.USER_ID)],
onDelete = ForeignKey.CASCADE)])
@Parcelize
data class Profile(@PrimaryKey(autoGenerate = true)
var userId: Int,
var name: String? = null):Parcelable{}
Here i have two tables in the DB.
Now,do i need to write migration code for creation of new table?
New contributor
nithin krishna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
refer this
– Basi
yesterday
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have two tables,person is already existing(added column userid as
foreign key)
@Entity(tableName = TABLE_NAME)
data class Person(
@PrimaryKey @ColumnInfo(name = CLIENT_ID) var id: Long,
@ColumnInfo(name = USER_ID)var userId : Int = 1) : Parcelable {}
this is the newly added class,which has foreign key of person
class(userid)
@Entity(tableName = Profile.TABLE_NAME,
foreignKeys = [ForeignKey(entity= Person::class,
parentColumns = [(Person.USER_ID)],
childColumns = [(Profile.USER_ID)],
onDelete = ForeignKey.CASCADE)])
@Parcelize
data class Profile(@PrimaryKey(autoGenerate = true)
var userId: Int,
var name: String? = null):Parcelable{}
Here i have two tables in the DB.
Now,do i need to write migration code for creation of new table?
New contributor
nithin krishna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have two tables,person is already existing(added column userid as
foreign key)
@Entity(tableName = TABLE_NAME)
data class Person(
@PrimaryKey @ColumnInfo(name = CLIENT_ID) var id: Long,
@ColumnInfo(name = USER_ID)var userId : Int = 1) : Parcelable {}
this is the newly added class,which has foreign key of person
class(userid)
@Entity(tableName = Profile.TABLE_NAME,
foreignKeys = [ForeignKey(entity= Person::class,
parentColumns = [(Person.USER_ID)],
childColumns = [(Profile.USER_ID)],
onDelete = ForeignKey.CASCADE)])
@Parcelize
data class Profile(@PrimaryKey(autoGenerate = true)
var userId: Int,
var name: String? = null):Parcelable{}
Here i have two tables in the DB.
Now,do i need to write migration code for creation of new table?
New contributor
nithin krishna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
nithin krishna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
nithin krishna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked yesterday
nithin krishna
12
12
New contributor
nithin krishna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
nithin krishna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
nithin krishna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
refer this
– Basi
yesterday
add a comment |
refer this
– Basi
yesterday
refer this
– Basi
yesterday
refer this
– Basi
yesterday
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
If you want to migrate your data from the previous version to the new version
then
Yes. You have to write the migration code.
If you only want to migrate schema and not data.
then no need to write migration logic. Just add fallbackToDestructiveMigration() in Room builder.
Example:
Room.databaseBuilder(appContext, AppDatabase.class, AppDatabase.DATABASE_NAME)
.fallbackToDestructiveMigration()
.build();
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
If you want to migrate your data from the previous version to the new version
then
Yes. You have to write the migration code.
If you only want to migrate schema and not data.
then no need to write migration logic. Just add fallbackToDestructiveMigration() in Room builder.
Example:
Room.databaseBuilder(appContext, AppDatabase.class, AppDatabase.DATABASE_NAME)
.fallbackToDestructiveMigration()
.build();
add a comment |
up vote
0
down vote
If you want to migrate your data from the previous version to the new version
then
Yes. You have to write the migration code.
If you only want to migrate schema and not data.
then no need to write migration logic. Just add fallbackToDestructiveMigration() in Room builder.
Example:
Room.databaseBuilder(appContext, AppDatabase.class, AppDatabase.DATABASE_NAME)
.fallbackToDestructiveMigration()
.build();
add a comment |
up vote
0
down vote
up vote
0
down vote
If you want to migrate your data from the previous version to the new version
then
Yes. You have to write the migration code.
If you only want to migrate schema and not data.
then no need to write migration logic. Just add fallbackToDestructiveMigration() in Room builder.
Example:
Room.databaseBuilder(appContext, AppDatabase.class, AppDatabase.DATABASE_NAME)
.fallbackToDestructiveMigration()
.build();
If you want to migrate your data from the previous version to the new version
then
Yes. You have to write the migration code.
If you only want to migrate schema and not data.
then no need to write migration logic. Just add fallbackToDestructiveMigration() in Room builder.
Example:
Room.databaseBuilder(appContext, AppDatabase.class, AppDatabase.DATABASE_NAME)
.fallbackToDestructiveMigration()
.build();
answered yesterday
Milind Mevada
1,325617
1,325617
add a comment |
add a comment |
nithin krishna is a new contributor. Be nice, and check out our Code of Conduct.
nithin krishna is a new contributor. Be nice, and check out our Code of Conduct.
nithin krishna is a new contributor. Be nice, and check out our Code of Conduct.
nithin krishna is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371799%2fis-it-neccessary-to-add-migration-if-new-table-is-added-in-room-database%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
refer this
– Basi
yesterday