简体   繁体   中英

Why does my second sqlite table throw an Exception?

I've got a DatabaseHelper class where I create the tables. The first table (recordings) is working fine, but the second one is throwing an Exception when I try to work with it (Insert/Select...).

here is my code from the DatabaseHelper:

 public void onCreate(SQLiteDatabase db) {

    String createTable="CREATE TABLE recordings" +
            "(_id INTEGER PRIMARY KEY AUTOINCREMENT," +
            " name VARCHAR(255) NOT NULL," +
            " datestart VARCHAR(255) NOT NULL" +
            ")";

    String createTable2="CREATE TABLE recording_image" +
            "(_id INTEGER PRIMARY KEY AUTOINCREMENT," +
            "imageurl VARCHAR(255) NOT NULL," +
            "imagetime INTEGER NOT NULL," +
            "prot_id INTEGER NOT NULL," +
            "FOREIGN KEY(prot_id) REFERENCES recordings(_id) ON DELETE CASCADE" +
            ")";

    db.execSQL(createTable);    
    db.execSQL(createTable2);
}

the Exception is:

no such table: recording_image.

What could cause this problem?

Yes, try to clear data of the application, and you can also look to the version of the db, If the version of the db you want to create are higher than the current db on the phone you have to delete and create again all the db.

please see : SQLiteOpenHelper

Hope that will help you :)

Problem solved. Just reinstalling the App or changing the Version number of the Database helped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM