๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ“ฑ| Android/โœ… | ์—๋Ÿฌํ•ด๊ฒฐ

[Android] Room์—์„œ ๋ฐ์ดํ„ฐ ๋ฌด๊ฒฐ์„ฑ์„ ํ™•์ธํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

by immgga 2022. 4. 11.

ํ•„์ž๋Š” room์„ ์ด์šฉํ•œ ์˜ˆ์ œ๋ฅผ ๋งŒ๋“ค๋‹ค๊ฐ€ ํ•œ ์˜ค๋ฅ˜๋ฅผ ๋งŒ๋‚ฌ๋‹ค.

 

์˜ค๋ฅ˜ ์ฝ”๋“œ

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์—์„œ ๋ฐ์ดํ„ฐ ๋ฌด๊ฒฐ์„ฑ์„ ํ™•์ธํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ์Šคํ‚ค๋งˆ๋ฅผ ๋ณ€๊ฒฝํ–ˆ์ง€๋งŒ ๋ฒ„์ „ ๋ฒˆํ˜ธ๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๊ฒƒ์„ ์žŠ์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋ฒ„์ „ ๋ฒˆํ˜ธ๋ฅผ ๋Š˜๋ฆฌ๋ฉด ๊ฐ„๋‹จํžˆ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๋ผ๊ณ  ํ•ด์„œ ๋ฒ„์ „ ๋ฒˆํ˜ธ๋ฅผ ๋ฐ”๊ฟ”๋ณด์•˜๋‹ค.

 

๊ธฐ์กด ์ฝ”๋“œ

@Database(entities = [UserEntity::class], version = 1)
abstract class UserDbBuilder: RoomDatabase() {
	...
}

 

 

๋ฐ”๊พผ ์ฝ”๋“œ

@Database(entities = [UserEntity::class], version = 2)	// version์„ ๋ฐ”๊ฟ”์ฃผ์„ธ์š”!
abstract class UserDbBuilder: RoomDatabase() {
	....
}

 

์ด๋ ‡๊ฒŒ ๋ฐ”๊พธ๋ฉด ๋งค์šฐ ๊ฐ„๋‹จํžˆ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

728x90