简体   繁体   English

外键sqlite 3删除1-n寄存器

[英]Foreign key sqlite 3 remove 1-n register

I have 2 tables, in sqlite 3 我有2张桌子,在sqlite 3中

Control and User. 控制和用户。

The control have the Name, user_id. 该控件的名称为user_id。

I want to delete the control when i delete the user. 我要在删除用户时删除控件。 So, if i delete all users with id = 10 i want to delete all controls with user_id = 10. Is there a way to do that in the database. 因此,如果我删除所有ID = 10的用户,我想删除所有user_id = 10的控件。有没有办法在数据库中做到这一点。 I'm already doing the CONSTRAINT "fk_user_id" FOREIGN KEY ("user_id") REFERENCES "tbl_user" ("id") ON DELETE CASCADE, and no luck. 我已经在删除CASCADE上进行了CONSTRAINT“ fk_user_id”外键(“ user_id”)参考“ tbl_user”(“ id”),但不走运。 The records still there. 记录仍然存在。

Thanks. 谢谢。

Solved 解决了

'db'=>array(
    'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
    'initSQLs'=>array(
    'PRAGMA foreign_keys = ON',
     ),
),

Need to add pragma to enable the foreign keys on init 需要添加编译指示以启用init上的外键

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM