Saving Data on Android



Download 19,28 Mb.
Pdf ko'rish
bet186/292
Sana24.01.2022
Hajmi19,28 Mb.
#407089
1   ...   182   183   184   185   186   187   188   189   ...   292
Bog'liq
Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019

QuizDatabase.kt
 under the 
data 

 db
 package and increase the database 
version by changing the 
version
 parameter value to 2 in the 
@Database
 notation:
@Database(entities = [(Question::class)
, (Answer::
class
)], 
version = 2) //version change
 
abstract
 
class
 
QuizDatabase
 : 
RoomDatabase
() { 
  
abstract
 
fun
 
questionsDao
()
: QuestionDao 
}
Build and run the app again and press 
START
....
And the app crashes again!
Open the logcat console to see the problem. You should see the message below:
A migration from 1 to 2 was required but not found. Please provide the necessary 
Migration path via RoomDatabase.Builder.addMigration(Migration ...) or allow for 
destructive migrations via one of the 
RoomDatabase.Builder.fallbackToDestructiveMigration
 methods.*
It looks like you're making some progress, since the error is different now. The error 
indicates that Room doesn't know how to change the database schema from 1 to 2, 
so it's giving you two options:
• Create a migration that goes from database schema 1 to 2.
• Call 
fallbackToDestructiveMigration()
 when building your database.
Saving Data on Android
Chapter 10: Migrations with Room
raywenderlich.com
177


The second option is the easiest one to implement since you only need to add a 
single line of code. The only problem with this approach is that you will lose all your 
data when changing the schema from version 1 to 2. This is fine for your app since 
you have a handy button to populate your database in the main menu, but it might 
not be a good idea for other projects where you want to preserve user data.
With the above in mind, you're going to follow the first approach and create a new 
migration. Create a new package under the 

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   182   183   184   185   186   187   188   189   ...   292




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish