开发者

Foreign key ON DELETE CASCADE is not working in Android 2.2

I have 2 tables:

db.execSQL("Create Table Location(LocationID INTEGER PRIMARY KEY AUTOINCREMENT, 
Latitude TEXT, Longitude TEXT," +
" CellID TEXT, MCC TEXT, MNC TEXT, LAC TEXT, SendTime TEXT DEFAULT
(datetime('now','localtime')), SignalStrength INTEGER, LocationType TEXT)");

db.execSQL("Create Tab开发者_JAVA技巧le Error_Exception(LocationID INTEGER, ExceptionID INTEGER
PRIMARY KEY AUTOINCREMENT, ModuleID TEXT, ClassName TEXT, ControlName TEXT, " +
"MethodName TEXT, ErrorDescription TEXT, ErrorDate TEXT DEFAULT
(datetime('now','localtime')),
FOREIGN KEY(LocationID) REFERENCES Location(LocationID)
ON DELETE CASCADE);");

When I tried to delete the rows in Error_Exception it is not deleting the rows in Location table.

I have tried with db.execSQL("PRAGMA foreign_keys=ON;"); also but still not working.

Please help


You've told your database to delete rows in Error_Exception when the referenced rows in Location are deleted. You seem to have things backward.

If you want to delete rows in Location when rows in Error_Exception are deleted, you need to drop the foreign key constraint in Error_Exception, and add a foreign key constraint in Location.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜