1

我正在使用糖 ORM 创建一个表,但收到没有这样的表的错误。即使在 Android Manifest 中将 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 Manifest 详细信息如下

 <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" />
4

2 回答 2

1
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.
于 2016-01-29T07:54:45.727 回答
0

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

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

并将其更改为例如 3:

   <meta-data android:name="VERSION" android:value="3" />
于 2016-05-10T06:17:34.503 回答