SQLite的列错误:表XXX没有名为YYY
我看着下面,在其他列,并发现匹配我的问题(据我可以告诉)什么:SQLite的列错误:表XXX没有名为YYY
Android : Table has no column named "variable name" MySql Database error
Error compiling insert into: No column named ID
Android SQLite issue - table ... has no column named
https://sqlite.org/foreignkeys.html
我收到以下错误的SQLite:
SQLiteDatabase: Error inserting zipCode=23456 address2= city=state address1=123 petName=qwerty phoneNumber=null vetName=zaw emailAddress=
android.database.sqlite.SQLiteException: table vets has no column named petName (code 1): , while compiling: INSERT INTO vets (zipCode,address2,city,address1,petName,phoneNumber,vetName,emailAddress) VALUES (?,?,?,?,?,?,?,?)
我有一种感觉,它与在VetTable外键做的,但我的研究还没有与了解发生了什么事情帮助我。
VetTable定义如下:
public class VetTable {
public static final String TABLE_VETS = "vets";
public static final String VET_ID = "vetId";
public static final String PET_ID = "petId";
public static final String VET_NAME = "vetName";
public static final String ADDRESS1 = "address1";
public static final String ADDRESS2 = "address2";
public static final String CITY = "city";
public static final String STATE = "state";
public static final String ZIP_CODE = "zipCode";
public static final String PHONE_NUMBER = "phoneNumber";
public static final String EMAIL_ADDRESS = "emailAddress";
public static final String SQL_CREATE =
"CREATE TABLE " + TABLE_VETS + "(" +
VET_ID + " INTEGER PRIMARY KEY UNIQUE, " +
PET_ID + " INTEGER, " +
VET_NAME + " TEXT, " +
ADDRESS1 + " TEXT, " +
ADDRESS2 + " TEXT, " +
CITY + " TEXT, " +
STATE + " TEXT, " +
ZIP_CODE + " TEXT, " +
PHONE_NUMBER + " TEXT, " +
EMAIL_ADDRESS + " TEXT, " +
"FOREIGN KEY(" + PET_ID + ") " +
"REFERENCES pets(petId));";
public static final String SQL_DELETE =
"DROP TABLE" + TABLE_VETS;
}
从DBHelper代码相关的代码如下:
public void addVetInfo(String name, String address1, String address2, String city, String state, String zip, String phone, String email){
try {
db = this.getWritableDatabase();
values.put(VET_NAME, name);
values.put(ADDRESS1, address1);
values.put(ADDRESS2, address2);
values.put(CITY, city);
values.put(CITY, state);
values.put(ZIP_CODE, zip);
values.put(PHONE_NUMBER, phone);
values.put(EMAIL_ADDRESS, email);
db.insert(TABLE_VETS, null, values);
} catch (SQLException e) {
e.printStackTrace();
}
}
如可以看到的petName不的一部分也不曾经被包括在VetTable ,也不是addVetInfo中参数列表的一部分。那么,SQLite做的是什么让它认为petName应该是VetTable中的一个列?
对于其他人谁是有这个SQLite的错误问题,看来,它在我的情况下有重复的是由于列的名称由CL指出我的帖子。当我纠正并重新编码时,它工作正常,没有错误。
因此,请确保您的列名称对于您的插入语句是正确的。
看起来像你的价值观变量已经有对象内部的价值,看看这个:
public void addVetInfo(String name, String address1, String address2, String city, String state, String zip, String phone, String email){
try {
db = this.getWritableDatabase();
//INITIALIZE YOUR VARIABLE VALUES HERE
ContentValues values = new ContentValues();
//if(name == "Enter vet name") name = null;
values.put(VET_NAME, name);
//if(address1 == "Enter address 1" || address1 == " ") address1 = null;
values.put(ADDRESS1, address1);
//if(address2 == "Enter address 2") address2 = null;
values.put(ADDRESS2, address2);
//if(city == "Enter city") city = null;
values.put(CITY, city);
//if(state == "Enter state") state = null;
values.put(CITY, state);
//if(zip == "Enter zip") zip = null;
values.put(ZIP_CODE, zip);
//if(phone == "Enter phone number") phone = null;
values.put(PHONE_NUMBER, phone);
//if(email == "Enter email address") email = null;
values.put(EMAIL_ADDRESS, email);
db.insert(TABLE_VETS, null, values);
} catch (SQLException e) {
e.printStackTrace();
}
}
我发现错误是由于CL的评论指出我有重复的“CITY”引用导致的。我无法想象为什么SQLite会说它与“petName”有什么关系。 – Jeff
有两个'put(CITY')调用,无论如何,显示的代码并不是实际得到执行的代码 –
CL,你是什么意思?我没有发布什么代码? – Jeff
CL,感谢您发现两个“CITY”电话! – Jeff