根据文档:
您可以设置注释处理器参数 (room.schemaLocation) 以指示 Room 将架构导出到文件夹中。尽管这不是强制性的,但最好在代码库中包含版本历史记录,并且应将该文件提交到版本控制系统中(但不要随应用一起提供!
因此,如果您不需要检查架构并且想要摆脱警告,只需添加到 您的 ,如下所示。exportSchema = false
RoomDatabase
@Database(entities = { YourEntity.class }, version = 1, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
//...
}
如果您遵循下面的答案@mikejonesguy,您将遵循文档:)中提到的良好实践。基本上,您将在文件夹中获得一个文件。它看起来像这样:.json
../app/schemas/
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "53db508c5248423325bd5393a1c88c03",
"entities": [
{
"tableName": "sms_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `message` TEXT, `date` INTEGER, `client_id` INTEGER)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER"
},
{
"fieldPath": "message",
"columnName": "message",
"affinity": "TEXT"
},
{
"fieldPath": "date",
"columnName": "date",
"affinity": "INTEGER"
},
{
"fieldPath": "clientId",
"columnName": "client_id",
"affinity": "INTEGER"
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"53db508c5248423325bd5393a1c88c03\")"
]
}
}
如果我的理解是正确的,那么每次数据库版本更新时,您都会获得这样的文件,以便您可以轻松跟踪数据库的历史记录。