没有这样的 table 存在异常,Sugar ORM Android

No Such table exist exception, Sugar ORM Android

我正在使用 sugar ORM 创建一个 table,但收到没有这样的 table 的错误。即使在 Android 清单中将 Version 更新为更高的值。

public class CachedVidcodes extends SugarRecord {
    private String vidcodeId;
    private String vidcodedownloadedPath;
    public CachedVidcodes(){
    }

    public CachedVidcodes(String vidcodeId, String vidcodedownloadedPath){
        this.vidcodeId = vidcodeId;
        this.vidcodedownloadedPath = vidcodedownloadedPath;
    }
    public String getVidcodeId() {
        return vidcodeId;
    }

    public void setVidcodeId(String vidcodeId) {
        this.vidcodeId = vidcodeId;
    }

    public String getVidcodedownloadedPath() {
        return vidcodedownloadedPath;
    }

    public void setVidcodedownloadedPath(String vidcodedownloadedPath) {
        this.vidcodedownloadedPath = vidcodedownloadedPath;
    }

}

Android 清单详情如下

 <meta-data
            android:name="DATABASE"
            android:value="vd.db" />
        <meta-data
            android:name="VERSION"
            android:value="2" />
        <meta-data
            android:name="QUERY_LOG"
            android:value="true" />
        <meta-data
            android:name="DOMAIN_PACKAGE_NAME"
            android:value="com.vf.vde.ormclasses" />
This problem can be solved by creating an empty "migration script file with new version". 
This can be simply done by following :
1. Create your new Sugar record class.
2. In Android manifest file just increase the DB version.
3. Add an empty migration script file named after the new DB version, placed under assets/sugar_upgrades. (example. 2.sql).
By doing this, it creates the new table without dropping/creating my old tables.

我通过增加 AndroidManifest 中 DB_VERSION 的数量解决了我的问题,因此您可以:

  <meta-data android:name="VERSION" android:value="2" />

并将其更改为 3:

   <meta-data android:name="VERSION" android:value="3" />