I've looked at the following, among others and have found nothing that matches my problem (as far as I can tell):
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
I'm getting the following SQLite error:
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 (?,?,?,?,?,?,?,?)
I have a feeling that it has to do with the foreign key in VetTable but my research hasn't helped me with understanding what's going on.
VetTable is defined as follows:
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;
}
The relevant code from DBHelper code is as follows:
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();
}
}
As can be seen petName is not part of nor has ever been included in VetTable, nor is it part of the argument list in addVetInfo. So, what is SQLite doing that makes it think that petName should be a column in VetTable?