Android
[Android] 개발 중에 Room DB 변경(feat. Kotlin)
김한토
2024. 12. 22. 14:06
반응형
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.
디비를 변경하면 이런식으로 오류가 뜬다.
근데 테스트 중이라 디비 버전을 업그레이드 하기가 거시기 저시기하다.
이때
//룸 디비 인스턴스를 생성할때 빌더 메서드를 변경하자.
Room.databaseBuilder(
context.applicationContext,
AppDatabase::class.java,
"ex_database"
).fallbackToDestructiveMigration().build()
//디비를 초기화할때 파일을 삭제하면 업그레이드 없이 디비를 삭제하고 다시 빌드할 수 있다.
//주의해야할점 기존에 디비에 있던 데이터 날라감.
DatabaseModule.initialize(this)
context.deleteDatabase("ex_database")
끝
반응형