Reputation: 409
I am trying to the insert a data en my table Tareas. I , m using a ORM (GreenDao).But when run my app, the log cat show that no exist a table named Tareas. I dont understand this because when I have created my database, the Tareas Table has a column named Tipo.
03-30 07:51:32.758 29389-29389/tipiwiny.greendao E/AndroidRuntime: FATAL EXCEPTION: main Process: tipiwiny.greendao, PID: 29389 android.database.sqlite.SQLiteException: table TAREAS has no column
named TIPO (code 1): , while compiling: INSERT INTO TAREAS ('_id','DURACION','TIPO','DESCRIPCION','USUARIO','REALIZADA') VALUES (?,?,?,?,?,?) at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889) at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500) at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58) at android.database.sqlite.SQLiteStatement.(SQLiteStatement.java:31) at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:994) at de.greenrobot.dao.internal.TableStatements.getInsertStatement(TableStatements.java:48) at de.greenrobot.dao.AbstractDao.insert(AbstractDao.java:293) at tipiwiny.greendao.CrearTarea.añadirTarea(CrearTarea.java:60) at tipiwiny.greendao.CrearTarea.access$000(CrearTarea.java:18) at tipiwiny.greendao.CrearTarea$1.onClick(CrearTarea.java:42) at android.view.View.performClick(View.java:4756) at android.view.View$PerformClick.run(View.java:19749) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
My database is defined how:
private static void createDatabase(Schema schema) {
Entity usuario = schema.addEntity("Usuario");
usuario.addIdProperty();
usuario.addStringProperty("nombre").notNull();
usuario.addStringProperty("apellidos").notNull();
usuario.addStringProperty("password").notNull();
usuario.addStringProperty("roll").notNull();
Entity habilidad = schema.addEntity("Habilidad");
habilidad.addIdProperty();
Property usuarioIdProperty = habilidad.addLongProperty("usuarioId").notNull().getProperty();
habilidad.addToOne(usuario, usuarioIdProperty);
habilidad.addIntProperty("tipo").notNull();
Entity tarea=schema.addEntity("Tareas");
tarea.addIdProperty();
tarea.addIntProperty("duracion").notNull();
tarea.addIntProperty("tipo").notNull();
tarea.addStringProperty("descripcion").notNull();
tarea.addStringProperty("usuario");
tarea.addBooleanProperty("realizada");
}
When you execute this code to generate the tables, the class TareasDao is created and the method createTable is:
/** Creates the underlying database table. */
public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "'TAREAS' (" + //
"'_id' INTEGER PRIMARY KEY ," + // 0: id
"'DURACION' INTEGER NOT NULL ," + // 1: duracion
"'TIPO' INTEGER NOT NULL ," + // 2: tipo
"'DESCRIPCION' TEXT NOT NULL ," + // 3: descripcion
"'USUARIO' TEXT," + // 4: usuario
"'REALIZADA' INTEGER);"); // 5: realizada
}
Upvotes: 1
Views: 1982
Reputation: 2984
Try uninstalling and reinstalling the app.
Details :
One possible reason could be that you created the table first, ran the migration and then added fields later.
So there could be two possible solutions :-
1 : Remove the app from your phone (uninstall) and it will remove all the tables with it. And then reinstalling will re-create all the tables.
2 : Change your onUpdate
method in DaoMaster to drop all the tables and recreating them.
/** WARNING: Drops all table on Upgrade! Use only during development. */
public static class DevOpenHelper extends OpenHelper {
public DevOpenHelper(Context context, String name, CursorFactory factory) {
super(context, name, factory);
Log.i("greenDAO", "DevOpenHelper: constructor called");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
//Remember to remove this line before moving to production.
dropAllTables(db,true);
onCreate(db);
}
}
Let me know if you need any help :)
Upvotes: 4