sqlite 是否可以从实体类生成CREATE TABLE SQL语句以轻松解决无效架构错误?

baubqpgj  于 2022-11-15  发布在  SQLite
关注(0)|答案(1)|浏览(136)

我正在使用Android Room中的一个有许多列的表。
我已经在SQLite中创建了表,并用Java创建了相应的实体类。当我编译应用程序时,出现以下错误:

E/AndroidRuntime: FATAL EXCEPTION: arch_disk_io_0 Process: com.my.app, PID: 8356 java.lang.RuntimeException: Exception while computing database live data. at androidx.room.RoomTrackingLiveData$1.run(RoomTrackingLiveData.java:92) at androidx.room.TransactionExecutor$1.run(TransactionExecutor.java:47) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:920) Caused by: java.lang.IllegalStateException: Pre-packaged database has an invalid schema: today(com.my.app.data.entity.TodayEntity). Expected: E/AndroidRuntime: TableInfo{name='today', columns={liturgyFK=Column{name='liturgyFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, timeID=Column{name='timeID', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, tPrayerFK=Column{name='tPrayerFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, tHymnFK=Column{name='tHymnFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, saintFK=Column{name='saintFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, oHymnFK=Column{name='oHymnFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, nPsalmodyFK=Column{name='nPsalmodyFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, vPrayerFK=Column{name='vPrayerFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, nBiblicalFK=Column{name='nBiblicalFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, massReadingFK=Column{name='massReadingFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, nPrayerFK=Column{name='nPrayerFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, sPsalmodyFK=Column{name='sPsalmodyFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, oPrayerFK=Column{name='oPrayerFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, vMagnificatFK=Column{name='vMagnificatFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, vHymnFK=Column{name='vHymnFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, lBenedictusFK=Column{name='lBenedictusFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, lHymnFK=Column{name='lHymnFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, invitatoryFK=Column{name='invitatoryFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, lPrayerFK=Column{name='lPrayerFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, vPsalmodyFK=Column{name='vPsalmodyFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, oVerseFK=Column{name='oVerseFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, lPsalmodyFK=Column{name='lPsalmodyFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, oPsalmodyFK=Column{name='oPsalmodyFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, oTeDeum=Column{name='oTeDeum', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='0'}, nHymnFK=Column{name='nHymnFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, oBiblicalFK=Column{name='oBiblicalFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, vIntercessionsFK=Column{name='vIntercessionsFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, lIntercessionsFK=Column{name='lIntercessionsFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, todayDate=Column{name='todayDate', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1, defaultValue='null'}, previousFK=Column{name='previousFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='1'}, tBiblicalFK=Column{name='tBiblicalFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, tPsalmodyFK=Column{name='tPsalmodyFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null' E/AndroidRuntime: }, sHymnFK=Column{name='sHymnFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, sBiblicalFK=Column{name='sBiblicalFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, oPatristicFK=Column{name='oPatristicFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, weekDayFK=Column{name='weekDayFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, lBiblicalFK=Column{name='lBiblicalFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, vBiblicalFK=Column{name='vBiblicalFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, sPrayerFK=Column{name='sPrayerFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}}, foreignKeys=[ForeignKey{referenceTable='lh_hymn_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[sHymnFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_psalmody_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[nPsalmodyFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_hymn_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[tHymnFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_office_verse_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[oVerseFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_hymn_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[vHymnFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_hymn_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[oHymnFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_reading_short_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[tBiblicalFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_prayer', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[nPrayerFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_reading_short_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[nBiblicalFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_prayer', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[sPrayerFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_prayer', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[vPrayerFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_psalmody_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[oPsalmodyFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_office_patristic_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[oPatristicFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_psalmody_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[tPsalmodyFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='saint', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[saintFK], referenceColumnNames=[saintID]}, ForeignKey{referenceTable='mass_reading_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[massReadingFK], referenceColumnNames=[liturgyFK]}, ForeignKey{referenceTable='lh_psalmody_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[lPsalmodyFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='liturgy', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[previousFK], referenceColumnNames=[liturgyID]}, ForeignKey{referenceTable='lh_reading_short_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[lBiblicalFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_gospel_canticle', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[lBenedictusFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_reading_short_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[vBiblicalFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_prayer', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[oPrayerFK], r E/AndroidRuntime: eferenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_psalmody_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[sPsalmodyFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_invitatory_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[invitatoryFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_intercessions_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[lIntercessionsFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_psalmody_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[vPsalmodyFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_hymn_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[lHymnFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_hymn_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[nHymnFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_gospel_canticle', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[vMagnificatFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_intercessions_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[vIntercessionsFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='liturgy', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[liturgyFK], referenceColumnNames=[liturgyID]}, ForeignKey{referenceTable='lh_office_biblical_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[oBiblicalFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_prayer', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[tPrayerFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_reading_short_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[sBiblicalFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_prayer', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[lPrayerFK], referenceColumnNames=[groupID]}], indices=[]} Found: E/AndroidRuntime: TableInfo{name='today', columns={liturgyFK=Column{name='liturgyFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, timeID=Column{name='timeID', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, tPrayerFK=Column{name='tPrayerFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, tHymnFK=Column{name='tHymnFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, saintFK=Column{name='saintFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, oHymnFK=Column{name='oHymnFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, nPsalmodyFK=Column{name='nPsalmodyFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, vPrayerFK=Column{name='vPrayerFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, nBiblicalFK=Column{name='nBiblicalFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, massReadingFK=Column{name='massReadingFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, nPrayerFK=Column{name='nPrayerFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, sPsalmodyFK=Column{name='sPsalmodyFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, oPrayerFK=Column{name='oPrayerFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, vMagnificatFK=Column{name='vMagnificatFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, vHymnFK=Column{name='vHymnFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, lBenedictusFK=Column{name='lBenedictusFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, lHymnFK=Column{name='lHymnFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, invitatoryFK=Column{name='invitatoryFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, lPrayerFK=Column{name='lPrayerFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, vPsalmodyFK=Column{name='vPsalmodyFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, oVerseFK=Column{name='oVerseFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, lPsalmodyFK=Column{name='lPsalmodyFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, oPsalmodyFK=Column{name='oPsalmodyFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, oTeDeum=Column{name='oTeDeum', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='0'}, nHymnFK=Column{name='nHymnFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, oBiblicalFK=Column{name='oBiblicalFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, vIntercessionsFK=Column{name='vIntercessionsFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, lIntercessionsFK=Column{name='lIntercessionsFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, todayDate=Column{name='todayDate', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1, defaultValue='null'}, previousFK=Column{name='previousFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='1'}, tBiblicalFK=Column{name='tBiblicalFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, tPsalmodyFK=Column{name='tPsalmodyFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null' E/AndroidRuntime: }, sHymnFK=Column{name='sHymnFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, sBiblicalFK=Column{name='sBiblicalFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, oPatristicFK=Column{name='oPatristicFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, lBiblicalFK=Column{name='lBiblicalFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, vBiblicalFK=Column{name='vBiblicalFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, sPrayerFK=Column{name='sPrayerFK', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}}, foreignKeys=[ForeignKey{referenceTable='lh_hymn_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[sHymnFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_psalmody_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[nPsalmodyFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_hymn_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[tHymnFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_office_verse_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[oVerseFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_hymn_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[vHymnFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_hymn_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[oHymnFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_reading_short_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[tBiblicalFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_prayer', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[nPrayerFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_reading_short_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[nBiblicalFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_prayer', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[vPrayerFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_prayer', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[sPrayerFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_psalmody_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[oPsalmodyFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_office_patristic_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[oPatristicFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_psalmody_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[tPsalmodyFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='saint', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[saintFK], referenceColumnNames=[saintID]}, ForeignKey{referenceTable='lh_psalmody_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[lPsalmodyFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='mass_reading_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[massReadingFK], referenceColumnNames=[liturgyFK]}, ForeignKey{referenceTable='liturgy', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[previousFK], referenceColumnNames=[liturgyID]}, ForeignKey{referenceTable='lh_reading_short_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[lBiblicalFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_gospel_canticle', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[lBenedictusFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_reading_short_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[vBiblicalFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_prayer', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[oPrayerFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_psalmody_join', onDelete='CASCADE', onUpdate='CASCADE', colum E/AndroidRuntime: nNames=[sPsalmodyFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_intercessions_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[lIntercessionsFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_invitatory_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[invitatoryFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_psalmody_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[vPsalmodyFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_hymn_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[nHymnFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_hymn_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[lHymnFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_intercessions_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[vIntercessionsFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_gospel_canticle', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[vMagnificatFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='liturgy', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[liturgyFK], referenceColumnNames=[liturgyID]}, ForeignKey{referenceTable='lh_prayer', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[tPrayerFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_office_biblical_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[oBiblicalFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_reading_short_join', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[sBiblicalFK], referenceColumnNames=[groupID]}, ForeignKey{referenceTable='lh_prayer', onDelete='CASCADE', onUpdate='CASCADE', columnNames=[lPrayerFK], referenceColumnNames=[groupID]}], indices=[]} at androidx.room.RoomOpenHelper.onCreate(RoomOpenHelper.java:82)

错误消息显示了预期的表和找到的表之间的差异,但以一种无序的方式显示了在大表中进行比较的困难。
我的问题是,是否有一种方法可以将实体类转换为CREATE TABLE语句,以便更容易地比较这两个CREATE TABLE以找到错误所在。

ifmq2ha2

ifmq2ha21#

我的问题是,是否有一种方法可以将实体类转换为CREATE TABLE语句,以便更容易地比较这两个CREATE TABLE语句以找出错误所在。
是的,Room在生成SQL时会代表您执行此操作。尝试以下方法:-
1.创建@Entity注解类。
1.将@Entity注解类包含在@Database注解抽象类的entities=参数中。
1.编译工程。
1.使用Android Studio的Android View找到Java(生成),找到与@Database注解类同名但后缀为**_impl的类。
1.在类中找到
createAllTables**方法。
1.每个表和索引都有一条_db.execSQL语句。您可以从其中复制和粘贴SQL。
1.您不必(不应该)创建ROOM_MASTER_TABLE,也不必使用INSERT命令插入ROOM_MASTER_TABLE。
示例

您可能希望使用实际的SQL语句来创建表,而不是进行比较。如果您有包含数据的现有表,则可以使用ALTER TABLE the_table RENAME TO the_renamed_original_table;重命名它们,然后在使用Room SQL创建表之后,使用INSERT INSERT INTERT TABLE FROM_RENAMED_ORIGURATE_TABLE*。

  • ALTER TABLE
  • INSERT
  • 请注意,您必须考虑外键约束,即父级必须存在,除非您关闭外键支持。
  • 启用外键支持

相关问题