我有我使用SQLiteOpenHelper
創建的現有數據庫,但現在我想移動到Sugar Orm並嘗試在現有數據庫中添加新表。我遵循Sugar orm頁面(Sugar Orm Configuration)的配置頁面上提到的所有要點。在現有的數據庫sqlite糖orm中創建表
這裏是我的配置看起來像,
AndroidManifest.xml中
<application
android:name=".application"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="DATABASE" android:value="database.db" />
<meta-data android:name="VERSION" android:value="5" />
<meta-data android:name="QUERY_LOG" android:value="true" />
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.example.in.smart" />
application.java(應用類)
public class application extends com.orm.SugarApp
{
private static Context instance;
public static Context get() {
return application.instance;
}
Model類
public class Now extends SugarRecord<Now> {
public String type = null;
public String name = null;
public String address = null;
public Date created;
public Now(){}
public Now(String type, String name,String address,Date created){
super();
this.type = type;
this.name = name;
this.address = address;
this.created = created;
}
}
@Override public void onCreate()
{
super.onCreate();
instance = getApplicationContext();
//ACRA.init(this);
}
}
增加數據處理
Now now = new Now(entry.getKey(), entry.getValue().get(i).name, entry.getValue().get(i).address, calendar.getTime());
now.save(); // throws exception here
,但我得到這個例外
E/SQLiteLog﹕ (1) no such table: NOW
E/SQLiteDatabase﹕ Error inserting ADDRESS=abc TYPE=Now NAME=tyy CREATED=1430229379156
android.database.sqlite.SQLiteException: no such table: NOW (code 1): , while compiling: INSERT INTO NOW(ADDRESS,TYPE,NAME,CREATED) VALUES (?,?,?,?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341)
at com.orm.SugarRecord.save(SugarRecord.java:126)
at com.orm.SugarRecord.save(SugarRecord.java:45)
我任何建議因爲它看起來像我做的一切權利。由於
你能告訴我們堆棧跟蹤嗎? –
已更新堆棧跟蹤 – user3290805
您是否也瀏覽了[數據庫遷移說明](http://satyan.github.io/sugar/migration.html)?你必須提高版本,並提供一個升級腳本來創建新的「Now」表格 - 這不會自動發生。 –