问题
I have tried to get an Android Project working with SugarORM. However, I am running into the following error:
Caused by: android.database.sqlite.SQLiteException: no such table: DOCUMENT (code 1): , while compiling: INSERT OR REPLACE INTO DOCUMENT(ID,CREATED) VALUES (?,?) ################################################################# Error Code : 1 (SQLITE_ERROR) Caused By : SQL(query) error or missing database. (no such table: DOCUMENT (code 1): , while compiling: INSERT OR REPLACE INTO DOCUMENT(ID,CREATED) VALUES (?,?)) #################################################################
In my AndroidManifest I have defined the android:name="com.orm.SugarApp"
in my application - Tag and included
<meta-data android:name="DATABASE" android:value="idea.db" />
<meta-data android:name="VERSION" android:value="1" />
also as child tags. I have removed
<meta-data android:name="QUERY_LOG" android:value="true" />
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.example" />
from the example as they don't change anything (and others had success in removing them). I have tried to Query the db first (with findById) to "force table creation" as explained in this post. Furthermore, I have tried doing something like
SugarDb sugarDb = new SugarDb(getApplicationContext()); new
File(sugarDb.getDB().getPath())
as described here.But this runs in an error as well. Furthermore I have disabled the InstantRun-Feature as described in a few posts and here (Sugar ORM No such table exception).
Can anybody point me the right direction how to get rid of the "error or missing database"-error?
回答1:
Are you sure <meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.example" />
doesn't change anything? Your link supporting that doesn't seem to go to the correct place. Regardless, follow the examples until the issue is fixed, then worry about what can be trimmed away!
You shouldn't need to be looking at the database file, not really sure why that's included.
Does your Document class extends SugarRecord? Without that, the table won't be created.
In general I think you should try running through the "Getting Started" again from scratch, without making any modifications to the code on the way.
回答2:
i had the same problem and in my case, it turned out that sugar orm version 1.4 had issues. Just update your gradle dependency to compile 'com.github.satyan:sugar:1.5'
This solved my problem
回答3:
If you use ProGuard you must edit proguard-rules.pro
Add this line to end. My SugarRecords ( models ) in models folder.
-keep class com.username.appname.models.** { *; }
And disable Instant Run function in Android Studio. I wrote a tutorial for SugarORM installation here
来源:https://stackoverflow.com/questions/38292116/sugarorm-error-or-missing-database