Adding a Suspect Property
Next, open Crime.kt and give Crime a property to hold the name of a suspect. Provide a default value – an empty string – so that you do not have to update places in your codebase where you create a Crime.
Listing 16.3 Adding a suspect property (Crime.kt
)
@Entity data class Crime( @PrimaryKey val id: UUID, val title: String, val date: Date, val isSolved: Boolean, val suspect: String = "" )
Since you updated your Crime class, and Room uses that class to create database tables for you, you need to make some changes to your database as well. Specifically, you need to increment the version of your CrimeDatabase class and tell Room how to migrate your database between the versions.
Room uses a versioning ...
Get Android Programming: The Big Nerd Ranch Guide, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.