Android No such table

1

I have an APP in which I was working with a sqlite table, all right, now I add another one, I put the code but it is not generated. In the DBHelper add in the onCreate the statement to create the table with db.execSQL but when I go to the activity I get the error that the table does not exist

public class LecturasDBHelper extends SQLiteOpenHelper{

public static final int DATABASE_VERSION = 2;
public static final String DATABASE_NAME = "Lecturas.db";

public LecturasDBHelper(Context context, String nombre, SQLiteDatabase.CursorFactory factory, int version) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE " + Columnas.TABLE_NAME + " (" etc..

and in the activity

LecturasDBHelper reclamobd = new LecturasDBHelper(MapsActivity.this, Constantes.DB_NAME, null, Constantes.VERSION);
SQLiteDatabase db = reclamobd.getWritableDatabase();

String selectQuery1 = "SELECT * FROM " + ReclamosColumnas.ColumnasReclamos.TABLE_NAME + " WHERE " + ReclamosColumnas.ColumnasReclamos.COLUMN_NAME_TERMINADO + " = 1";
Cursor cursor1 = db.rawQuery(selectQuery1, null);

This same code works well with the previous table, but now it does not generate the new table within the same DB, is something missing?

    
asked by desarrollosTELLO 29.08.2018 в 00:33
source

2 answers

0

Regarding the error:

no such table: Tabla (code 1): ....

you indicate this problem:

  

This same code works well with the previous table, but now   does not generate the new table within the same DB

What you want to do is a change in the structure of the elements of the database, in this case the table, it will not be created again unless you make any of these 3 points, anybody will have to call the method again onCreate(SQLiteDatabase db) and create the table:

1) You can go to applications and remove the cache of your application.

2) Delete the application and install again.

3) Change the version of the database, this would be done in the class that extends from SQLiteOpenHelper

public class LecturasDBHelper extends SQLiteOpenHelper{

     public static final int DATABASE_VERSION = 3; //Originalmente era 2
...
...
  

Important: The 1) and 2) point can be made while testing but in   production this can not be done, for this you must make the point 3) because when you upload a   update of your application that implies a change in the content   of the database or the structure of the tables you must increase the   value of the database version.

    
answered by 29.08.2018 в 02:43
-1

I do not think that is the solution, public static final int DATABASE_VERSION = 2; It serves for that, if you do any, change in the database, even if the app is already in the marquet, if you add or delete tables to the database, you must change it, the app to see that the version of the database is different is updated.

    
answered by 29.08.2018 в 00:58