无法创建数据库 java.sql.SQLException:找不到名称为 ... class 的已声明字段

Unable to create databases java.sql.SQLException: Could not find declared field with name ... for class

嗨!

我正在使用 android studio 并从事 android 项目。我试图创建一个大约有 57 table 的数据库。我收到以下错误消息:

Unable to create datbases java.sql.SQLException: Could not find declared field with name 'warehouseOverstore' for class com.icecube.iceman.model.dto.AddressEntity

In addressEntity hasn't got any field called warehouseOverstore. Never was declared too. In ormlite_config doesn't containing any references to warehouseOverstore.

如果我省略了 createTable 指令,应用程序 运行 不会出现任何错误。有什么问题吗?

ormlite_config 摘录:

# --table-start--
dataClass=com.icecube.iceman.model.dto.AddressEntity
tableName=address
# --table-fields-start--
fieldName=id
columnName=_id
generatedId=true
fieldName=name
columnName=name
fieldName=zip
columnName=zip
fieldName=country
columnName=country
fieldName=city
columnName=city
fieldName=district
columnName=district
fieldName=street
columnName=street
fieldName=streetnumber
columnName=streetNumber
fieldName=block
columnName=block
fieldName=building
columnName=building
fieldName=type
columnName=type
# --table-fields-end--
# --table-end--

地址实体:

@DatabaseTable(tableName="address" )
public class AddressEntity implements Serializable {

private static final long serialVersionUID = 1L;

//----------------------------------------------------------------------
// ENTITY PRIMARY KEY ( BASED ON A SINGLE FIELD )
//----------------------------------------------------------------------
@DatabaseField(generatedId = true, columnName = "_id")
private Integer    id           ;


//----------------------------------------------------------------------
// ENTITY DATA FIELDS 
//----------------------------------------------------------------------
@DatabaseField(columnName="name")
private String     name         ;

@DatabaseField(columnName="zip", canBeNull=false)
private String     zip          ;

@DatabaseField(columnName="country", canBeNull=false)
private String     country      ;

@DatabaseField(columnName="city", canBeNull=false)
private String     city         ;

@DatabaseField(columnName="district")
private String     district     ;

@DatabaseField(columnName="street")
private String     street       ;

@DatabaseField(columnName="streetNumber")
private String     streetnumber ;

@DatabaseField(columnName="block")
private String     block        ;

@DatabaseField(columnName="building")
private String     building     ;

@DatabaseField(columnName="type", canBeNull=false)
private String     type         ;

// After that just constructor and getter/setters. No reference on warehauseOverstore

感谢您的帮助。

您是从头开始创建此项目还是试图修改现有项目? 如果这是一个新项目,为什么要使用 OrmLite? Google 最近创建了 Room,我真的推荐你使用它 ;)。我也用过OrmLite,但是它会产生很长的冷启动,所以我决定离开它。

如果您真的需要 OrmLite,您的项目中是否有名为 warehouseOverstore 的变量?

DaoManager.clearCache();命令解决了它。将它放在 class 构造函数中,它扩展了 OrmLiteSqliteOpenHelper

您需要通过 运行 OrmLiteConfigUtil.java

重新生成 ormlite_config 文件