Accounts table containts two fk, colTermID and colStatID. Both tables already exist and work fine but is unknown to Accounts table. I've tried removing the Account create table and running to create the first two then rerunning with the Account create table back in place but still the same error.
I checked with DB Browser whether or not TermsTable and StatusTable have both been created and they have and have the corresponding colTerms/StatID in it's proper place.
Is there something I'm missing?
onCreate snippet:
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + termsTable + " (" + colTermsID + " INTEGER PRIMARY KEY , " + colTermsClass + " TEXT)");
db.execSQL("CREATE TABLE " + statTable + " (" + colStatusID + " INTEGER PRIMARY KEY , " + colStatClass + " TEXT)");
db.execSQL("CREATE TABLE " + accountsTable + " (" + colID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
colName + " TEXT, " +
colAmount + " Integer, " +
colPurpose + " TEXT, " +
colTerms +" INTEGER NOT NULL, " +
colDate + " TEXT, " +
colStatus +" INTEGER NOT NULL," +
"FOREIGN KEY (" + colTermsID + ") REFERENCES " + termsTable + " (" + colTermsID + ") " + "," +
"FOREIGN KEY (" + colStatusID + ") REFERENCES " + statTable + " (" + colStatusID + "));");
db.execSQL("CREATE VIEW " + viewAccs +
" AS SELECT " + accountsTable + "." + colID + " AS _id," +
" " + accountsTable + "." + colName + "," +
" " + accountsTable + "." + colAmount + "," +
" " + accountsTable + "." + colPurpose + "," +
" " + termsTable + "." + colTermsClass + "" +
" FROM " + accountsTable + " JOIN " + termsTable +
" ON " + accountsTable + "." + colTerms + " =" + termsTable + "." + colTermsID +
" " + accountsTable + "." + colDate + "," +
" " + statTable + "." + colStatClass + "" +
" FROM " + accountsTable + " JOIN " + statTable +
" ON " + accountsTable + "." + colStatus + " =" + statTable + "." + colStatusID
);
InsertTerms(db);
InsertStatus(db);
}
onUpgrade snippet:
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS "+ accountsTable);
db.execSQL("DROP TABLE IF EXISTS "+ termsTable);
db.execSQL("DROP TABLE IF EXISTS "+ statTable);
db.execSQL("DROP TRIGGER IF EXISTS acc_id_trigger");
db.execSQL("DROP TRIGGER IF EXISTS acc_id_trigger22");
db.execSQL("DROP TRIGGER IF EXISTS fk_accterm_termid");
db.execSQL("DROP TRIGGER IF EXISTS fk_accstat_statid");
db.execSQL("DROP VIEW IF EXISTS "+ viewAccs);
onCreate(db);
}
Logcat of love:
02-15 22:00:46.773: E/AndroidRuntime(6782): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jc.creditcradle/com.example.jc.creditcradle.AccountManager}: android.database.sqlite.SQLiteException: unknown column "TermsID" in foreign key definition (code 1): , while compiling: CREATE TABLE Accounts (AccountID INTEGER PRIMARY KEY AUTOINCREMENT, AccountName TEXT, Amount Integer, Purpose TEXT, Terms INTEGER NOT NULL, DateCreated TEXT, Status INTEGER NOT NULL,FOREIGN KEY (TermsID) REFERENCES Terms (TermsID) ,FOREIGN KEY (StatID) REFERENCES Status (StatID));
Aucun commentaire:
Enregistrer un commentaire