外键 ON DELETE CASCADE 在 Android 2.2 中不起作用
我有 2 个表:
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 Table 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);");
当我尝试删除 Error_Exception
中的行时,它并没有删除 Location
表中的行。
我也尝试过 db.execSQL("PRAGMAforeign_keys=ON;"); 但仍然不起作用。
请帮忙
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 Table 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已告诉数据库在删除 Location 中引用的行时删除 Error_Exception 中的行。看来你的事情有些落后了。
如果要在删除 Error_Exception 中的行时删除 Location 中的行,则需要删除 Error_Exception 中的外键约束,并在 Location 中添加外键约束。
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.