[英]creating tables in existing database sqlite sugar orm
我有使用SQLiteOpenHelper
创建的现有数据库,但是现在我想移至Sugar Orm并尝试在现有数据库中添加新表。 我遵循糖orm页面( 糖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;
}
模型类
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)
任何建议对我来说都好像我做对了所有事情。 谢谢
同样的事情发生在我身上,解决方案仅是清单中的数据库版本:
从:
<meta-data
android:name="VERSION"
android:value="2" />
至:
<meta-data
android:name="VERSION"
android:value="3" />
问候。
INSERT INTO
语句无效:
INSERT INTO NOW(ADDRESS,TYPE,NAME,CREATED) VALUES (?,?,?,?,?)
您尝试插入5个值而不是4。(请注意5个问号)。
我猜SugarRecord
包含一个必填的ID。
Now now = new Now(entry.getKey(), entry.getValue().get(i).name, entry.getValue().get(i).address, calendar.getTime());
有同样的问题。 检查您的条目之一是否为“ null”。
Sugar ORM不支持空值。 请也增加数据库的版本。
尝试禁用即时运行,sugar orm不适用于即时运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.