0

i am creating a tow tables in my android project using SQLite but the second table Uploadbook is not creating

code:

public class DBConnection extends SQLiteOpenHelper {
    public static final String DbName="MyProject.db";
    SQLiteDatabase db;




    public DBConnection(Context context){
        super(context,DbName,null,1);

    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table IF NOT EXISTS UploadBook(BId INTEGER primary key AUTOINCREMENT,Bname TEXT,Bcategory TEXT,AuthorName TEXT,Bdecs TEXT, Brate REAL, country TEXT,  city TEXT,  address TEXT, phoneno INTEGER,  Email Text,  Bprice REAL, Brent REAL,  Bdeposit REAL,   Bimage BLOB ,FOREIGN KEY (Email) REFERENCES signup(Email))");

        db.execSQL("create table IF NOT EXISTS signup(ID INTEGER PRIMARY KEY AUTOINCREMENT,Name TEXT,Email TEXT,Password TEXT,REpassword TEXT)");

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("Drop table if EXISTS UploadBook");

        db.execSQL("DROP TABLE IF EXISTS signup");
        onCreate(db);

    }
Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
m.karman
  • 65
  • 1
  • 1
  • 4
  • Do you get an error message? If so, can you edit your question to include it please? – GrandMasterFlush Feb 25 '17 at 15:21
  • no error message.! – m.karman Feb 25 '17 at 15:24
  • UploadBook is the first table. Does that mean neither table is created? If so, my guess is your database was created in some previous run of the code, but you added the create table statements later. You need to delete the database and re-create it. – Dave Feb 25 '17 at 16:14
  • I suggest uninstalling your app completely and trying again. – Code-Apprentice Feb 25 '17 at 16:17
  • 1
    For further explanation of my previous comment, `onCreate` does not run every time your app is started. The database is persistent beyond a single run of your app. You can override `onOpen` and put some log statement to see that the database is opened. Put a log in `onCreate` also for comparison. Only one of those two will execute each time the app is run. – Dave Feb 25 '17 at 16:18
  • Whenever you test changes to onCreate() you must remove the app and then reinstall it. – Code-Apprentice Feb 25 '17 at 16:22

0 Answers0