简体   繁体   中英

Android not making another table in the database

Here is my code in Database Creation

public void onCreate(SQLiteDatabase db) {

    db.execSQL("create table " + TBL_NAME_Arth + " (ID INTEGER PRIMARY KEY AUTOINCREMENT," +
            "RECIPE_NAME TEXT,ING_1 TEXT,ING_2 TEXT,ING_3 TEXT,ING_4 TEXT,ING_5 TEXT,ING_6 TEXT,ING_7 TEXT,ING_8 TEXT,ING_9 TEXT,ING_10 TEXT+" +
            "ING_12 TEXT,ING_12 TEXT,ING_13 TEXT,ING_14 TEXT,ING_15 TEXT,ING_16 TEXT,ING_17 TEXT,ING_18 TEXT,ING_19 TEXT,ING_20 TEXT)");

    db.execSQL("create table " + TBL_NAME_Dia + " (ID INTEGER PRIMARY KEY AUTOINCREMENT," +
            "RECIPE_NAME TEXT,ING_1 TEXT,ING_2 TEXT,ING_3 TEXT,ING_4 TEXT,ING_5 TEXT,ING_6 TEXT,ING_7 TEXT,ING_8 TEXT,ING_9 TEXT,ING_10 TEXT+" +
            "ING_12 TEXT,ING_12 TEXT,ING_13 TEXT,ING_14 TEXT,ING_15 TEXT,ING_16 TEXT,ING_17 TEXT,ING_18 TEXT,ING_19 TEXT,ING_20 TEXT)");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    onCreate(db);
    db.execSQL("DROP TABLE IF EXISTS " + TBL_NAME);
    db.execSQL("DROP TABLE IF EXISTS " + TBL_NAME_Arth);
    db.execSQL("DROP TABLE IF EXISTS " + TBL_NAME_Dia);

}

This codes is for calling the creation myDb = new DatabaseHelper(this);

Move the line onCreate(db); after the drop statements in onUpgrade() method. Currently, you are creating your tables and dropping them after that.

But, in onUpgrade() method you should drop the existing tables first and than create the new ones.

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