我有这段代码用于在 android 应用程序中创建我的 sqlLite DB:
private static final String CREATE_TABELLA_PERSONE = "CREATE TABLE TB_PERSONE "
+ "(_ID integer,"
+ "CODICE_PERSONA text not null, DESC_PERSONA text null, "
+ "PRIMARY KEY (CODICE_PERSONA));";
和
private static final String CREATE_TABELLA_USCITE = "CREATE TABLE AN_USCITE "
+ "(_ID integer, "
+ "CODICE_USCITA text null, SCADENZA text null, DATA text null,"
+ "PERSONA text not null REFERENCES TB_PERSONE(CODICE_PERSONA) ON DELETE NO ACTION ON UPDATE CASCADE,PRIMARY KEY(CODICE_USCITA));";
当我在“TB_PERSONE”中调用删除一行的函数时
public int SQLdelete(String tabella, String id) {
return database.delete(tabella, "_ID=" + id, null);
}
该应用程序向我显示此错误:
04-27 11:15:27.152: E/AndroidRuntime(22031): FATAL EXCEPTION: main
04-27 11:15:27.152: E/AndroidRuntime(22031): android.database.sqlite.SQLiteConstraintException:
foreign key constraint failed (code 19)
04-27 11:15:27.152: E/AndroidRuntime(22031): at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method)
04-27 11:15:27.152: E/AndroidRuntime(22031): at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:727)
04-27 11:15:27.152: E/AndroidRuntime(22031): at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754)
04-27 11:15:27.152: E/AndroidRuntime(22031): at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64)
04-27 11:15:27.152: E/AndroidRuntime(22031): at android.database.sqlite.SQLiteDatabase.delete(SQLiteDatabase.java:1494)
04-27 11:15:27.152: E/AndroidRuntime(22031): at it.jackpot21.personalmoney.DbAdapter.SQLdelete(DbAdapter.java:89)
04-27 11:15:27.152: E/AndroidRuntime(22031): at it.jackpot21.personalmoney.PersoneActivity$5.onClick(PersoneActivity.java:215)
04-27 11:15:27.152: E/AndroidRuntime(22031): at android.view.View.performClick(View.java:4084)
04-27 11:15:27.152: E/AndroidRuntime(22031): at android.view.View$PerformClick.run(View.java:16966)
04-27 11:15:27.152: E/AndroidRuntime(22031): at android.os.Handler.handleCallback(Handler.java:615)
04-27 11:15:27.152: E/AndroidRuntime(22031): at android.os.Handler.dispatchMessage(Handler.java:92)
04-27 11:15:27.152: E/AndroidRuntime(22031): at android.os.Looper.loop(Looper.java:137)
04-27 11:15:27.152: E/AndroidRuntime(22031): at android.app.ActivityThread.main(ActivityThread.java:4745)
04-27 11:15:27.152: E/AndroidRuntime(22031): at java.lang.reflect.Method.invokeNative(Native Method)
04-27 11:15:27.152: E/AndroidRuntime(22031): at java.lang.reflect.Method.invoke(Method.java:511)
04-27 11:15:27.152: E/AndroidRuntime(22031): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-27 11:15:27.152: E/AndroidRuntime(22031): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-27 11:15:27.152: E/AndroidRuntime(22031): at dalvik.system.NativeStart.main(Native Method)
有人可以帮我吗?
非常感谢!:)
编辑:
我通过把ON DELETE SET NULL
.
非常感谢!