【发布时间】:2019-04-16 13:41:12
【问题描述】:
我在数据库中创建了一个外键约束ON DELETE SET DEFAULT,并分配了一个默认值。
我尝试了什么:
- 在 App.Config 中:我在连接字符串中添加了“foreign keys=true;”。
- I edited the dataset XSD
- 我更改了 WinForm 上的 DataSet 并在那里强制执行:EnforceConstraints = true
- 我检查了,我的 SQLite 版本足够高,可以支持这个(我使用 v1.0.110.0)
- 我无法使用 PRAGMA 命令(如下所示:Enabling Foreign key constraints in SQLite),因为数据绑定到控件。
- 我重建了项目。
- 我在 SqliteStudio 中尝试过,约束有效,但在 C# 中无效。
我可能错过了什么......
更新: App.Config 以某种方式与项目设置不同步,因此额外的参数不包含在构建中。但是通过项目属性添加参数会引发错误。
"Data Source=.\InventoryManagerDatabase.db;foreign keys=true;"
错误:
System.InvalidOperationException: '未知的连接字符串参数'外键'。'
显然这个参数不存在?我检查了各种资源,包括 Enabling Foreign key constraints in SQLite 和 SQLite EF6 programmatically set connection string at runtime 但这很奇怪...... SQLite 删除了这个参数还是重命名了它?
我也尝试过(以及区分大小写的组合):
EnforceFKConstraints=True;
foreign key=true;
foreign keys=true;
foreign_keys=true;
ForeignKeys=true;
Foreign Key Constraints=true;
PRAGMA foreign_keys = ON; // obviously does not work
但没有任何效果......
【问题讨论】: