Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by increasing the version number.

지프치프·2021년 11월 15일
0

Issue(error)

목록 보기
9/20

개요

개인 프로젝트를 하던 도중 에러가 발생했다.

E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1
    Process: com.example.quickmemo, PID: 3806
    java.lang.IllegalStateException: Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by increasing the version number.
        at androidx.room.RoomOpenHelper.checkIdentity(RoomOpenHelper.java:154)
        at androidx.room.RoomOpenHelper.onOpen(RoomOpenHelper.java:135)
        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onOpen(FrameworkSQLiteOpenHelper.java:142)
        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:428)
        at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:317)
        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:92)
        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:53)
        at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:476)
        at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:281)
        at com.example.quickmemo.activity.room.dao.MemoDAO_Impl.getMemoList(MemoDAO_Impl.java:126)
        at com.example.quickmemo.activity.fragment.MemoListFragment$onViewCreated$1.invokeSuspend(MemoListFragment.kt:48)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:561)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:727)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:667)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:655)
I/Process: Sending signal. PID: 3806 SIG: 9

Room Database에 기능을 추가하다가 발생하였는데
해결방법은 매우 간단했다.

해결

Room은 수정될 때마다 버전업과 함께 Migration을 해주어야한다.
하지만 Mirgation을 생략할 수 있는 방법이 있다.
절대 귀찮은 것이 아니다

instance = Room.databaseBuilder(context.applicationContext, MemoRoomDatabase::class.java, "memoRoom.db")
                    .allowMainThreadQueries()
                    .fallbackToDestructiveMigration()
                    .build()

instance를 반환할 때 fallbackToDestructiveMigration()
추가해주면 된다.

Mirgation 하는 방법은 차후에 포스팅해보도록 하겠다.

개인적으로 공부했던 것을 바탕으로 작성하다보니
잘못된 정보가 있을수도 있습니다.
인지하게 되면 추후 수정하겠습니다.
피드백은 언제나 환영합니다.
읽어주셔서 감사합니다.

profile
지프처럼 거침없는 개발을 하고싶은 개발자

0개의 댓글