我尝试在我的数据库中插入一个新列,就像我一直在做的那样但是由于某些未知的原因,另一个列有问题,直到我做了最新的添加。这是错误输出:
SQLiteException: no such column: DistanceFromHotel (code 1): , while compiling: UPDATE contents SET Longitude=?,WebsiteURL=?,Phone=?,PostalCode=?,Email=?,Latitude=?,MainImageURL=?,ID=?,DistanceFromHotel=?,OnlineBookingURL=? WHERE ID=77
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:896)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:507)
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.updateWithOnConflict(SQLiteDatabase.java:1604)
at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1552)
at com.hotelstayapp.android.utilities.Database.importContent(Database.java:443)
这是我尝试与数据库通信并获取错误的地方:
public long importContent(ContentSync data){
Long ret=null;
Content content=new Content();
SQLiteDatabase database = this.getWritableDatabase();
ContentValues values = new ContentValues();
if(data.IsDeleted){
database.delete(TABLE_CONTENTS,"ID="+data.ID,null);
return 1;
} else {
values.put("ID", data.ID);
values.put("PostalCode", data.PostalCode);
if(data.Latitude!=0){
values.put("Latitude", data.Latitude);
} else {
values.putNull("Latitude");
}
if(data.Latitude!=0) {
values.put("Longitude", data.Longitude);
} else {
values.putNull("Longitude");
}
values.put("Phone", data.Phone);
values.put("Email", data.Email);
values.put("WebsiteURL", data.WebsiteURL);
values.put("OnlineBookingURL", data.OnlineBookingURL);
values.put("MainImageURL", data.MainImage);
values.put("DistanceFromHotel",data.DistanceFromHotel);
if(isContentRecord(data.ID)){ //update
ret=data.ID;
database.update(TABLE_CONTENTS,values,"ID="+data.ID,null);
} else {
ret=database.insert(TABLE_CONTENTS,null,values);
}
return ret;
}
}
我拉了数据库并检查了5次,该列存在。我读过类似的问题,但我找不到解决问题的方法。有任何想法吗?提前谢谢。
更新
以下是我要更新的表的结构: