I have a database created but one of the tables is not being created. Have one table called 'campanha' and work perfectly but when i try to create another one (user) even without columns says 'no such table: user'
Already try:
this.database = this.getWritableDatabase();
Create table without columns to make sure isnt sql problem
Creating a different file to create a different table - same problem
Code:
public class UserBDHelper extends SQLiteOpenHelper {
private static final int DB_VERSION = 1;
private static final String DB_NAME = "tesp-psi-pl2-07-web";
private static final String TABLE_NAME = "user";
private static final String USERNAME = "username";
private static final String EMAIL = "email";
private static final String ACCESSTOKEN = "accesstoken";
private static final String NOMEPROPRIO = "userNomeProprio";
private static final String APELIDO = "userApelido";
private static final String MORADA = "userMorada";
private static final String DATANASC = "userDataNasc";
private final SQLiteDatabase database;
public UserBDHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
this.database = this.getWritableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
String createUsertable = "CREATE TABLE " + TABLE_NAME +
"(id INTEGER, " +
USERNAME + " TEXT NOT NULL, " +
EMAIL + " TEXT NOT NULL, " +
ACCESSTOKEN + " TEXT NOT NULL, " +
NOMEPROPRIO + " TEXT NOT NULL, " +
APELIDO + " TEXT NOT NULL, " +
DATANASC + " TEXT NOT NULL, " +
MORADA + " TEXT NOT NULL " +
")";
db.execSQL(createUsertable);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
this.onCreate(db);
}
public void removeAllUsers(){
this.database.delete(TABLE_NAME,null,null);
}
}
The erro in the log is :-
android.database.sqlite.SQLiteException: no such table: user (code 1): , while compiling: DELETE FROM user
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.delete(SQLiteDatabase.java:1496)
at pt.ipleiria.estg.dei.amsi.fixbyte.modelo.UserBDHelper.removeAllUsers(UserBDHelper.java:109)