Home:ALL Converter>SQLite error an android: foreign key mismatch on Insert on Database

SQLite error an android: foreign key mismatch on Insert on Database

Ask Time:2012-03-31T01:13:06         Author:user675319

Json Formatter

and thanks in advance! I'm going crazy with an error, when trying to insert in a table that has foreign keys. Values exist, are the same type and are not-null... And the more funny is that first time fails, and only first! The other inserts works perfectly! I've tried to delete insert and repeat, and the error is not throwed again... Only first time! I'm trying it on Android 2.2 (Froyo), and before was in 2.1 with no foreign keys.

Sorry for the big "message" but i'm lost!

error:


03-30 16:59:56.333: E/AndroidRuntime(28007): android.database.sqlite.SQLiteException: foreign key mismatch: , while compiling: INSERT INTO productoslista(idProducto, idUnidad, comprado, idLista, comentario, cantidad) VALUES(?, ?, ?, ?, ?, ?);
03-30 16:59:56.333: E/AndroidRuntime(28007):    at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
03-30 16:59:56.333: E/AndroidRuntime(28007):    at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
03-30 16:59:56.333: E/AndroidRuntime(28007):    at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
03-30 16:59:56.333: E/AndroidRuntime(28007):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
03-30 16:59:56.333: E/AndroidRuntime(28007):    at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:36)
03-30 16:59:56.333: E/AndroidRuntime(28007):    at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1145)
03-30 16:59:56.333: E/AndroidRuntime(28007):    at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1536)
03-30 16:59:56.333: E/AndroidRuntime(28007):    at android.database.sqlite.SQLiteDatabase.insertOrThrow(SQLiteDatabase.java:1432)

tables:


CREATE TABLE [ProductosLista] (
[idLista] INTEGER  NOT NULL,
[idProducto] INTEGER  NOT NULL,
[cantidad] INTEGER  NOT NULL,
[idUnidad] INTEGER  NOT NULL,
[comprado] INTEGER  NOT NULL,
[comentario] TEXT,
PRIMARY KEY ([idLista],[idProducto],[comentario]),
FOREIGN KEY (idLista) REFERENCES Listas(idLista),
FOREIGN KEY (idProducto) REFERENCES Productos(idProducto),
FOREIGN KEY (idUnidad) REFERENCES Unidades(idUnidad)



CREATE TABLE [Listas] (
[idLista] INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL,
[descripcion] TEXT  UNIQUE NOT NULL,
[fechaCreacion] INTEGER  NOT NULL,
[visible] TEXT  NOT NULL,
[estadoCompra] INTEGER NOT NULL
);

CREATE TABLE [Unidades] (
[idUnidad] INTEGER  NOT NULL,
[idIdioma] INTEGER  NOT NULL,
[abreviatura] TEXT  NOT NULL,
[descripcion] TEXT  NOT NULL,
--PRIMARY KEY ([idUnidad],[idIdioma]),
FOREIGN KEY (idIdioma) REFERENCES Idiomas(idIdioma)
);

CREATE TABLE [Productos] (
[idProducto] INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL,
[idPadre] INTEGER  NOT NULL,
[idCategoria] INTEGER  NOT NULL,
[idTipoAlimentacion] INTEGER NOT NULL,
[eliminado] INTEGER NOT NULL,
[imagen] INTEGER,
FOREIGN KEY (idPadre) REFERENCES Productos(idProducto),
FOREIGN KEY (idCategoria) REFERENCES Categorias(idCategoria)
);

Author:user675319,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/9947493/sqlite-error-an-android-foreign-key-mismatch-on-insert-on-database
Douglas Costa :

You have to delete your database and run the application again. You will delete your database with the emulator open, then open the tab file explorer and go up to the folder where the bank. Sorry for english mistakes I'm Brazilian.",
2012-06-13T14:07:59
yy