明确知道 SQLite 中哪个 FOREIGN KEY 约束失败 [英] Knowing specifically which FOREIGN KEY constraint failed in SQLite

查看:19
本文介绍了明确知道 SQLite 中哪个 FOREIGN KEY 约束失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到 SQLite 错误消息FOREIGN KEY 约束失败".这是完整的错误信息(除了 SQL 查询的一部分),并没有帮助.(事实上​​,它与 Oracle 错误消息一样好(或坏).)我需要知道约束的名称来调查我的程序中的问题.不幸的是,没有网络支持平台可以与 SQLite 社区讨论这个问题.有人知道如何从该 SQLite 库中获取有关错误的更多信息吗?

I get the SQLite error message "FOREIGN KEY constraint failed". That's the complete error information (besides a part of the SQL query) and it's not helpful. (In fact it's just as good (or bad) as Oracle error messages.) I need to know the name of the constraint to investigate the issue in my program. Unfortunately there's no web support platform to discuss this with an SQLite community. Does somebody know how to get more information about the error out of that SQLite library?

我专门为 .NET 使用 System.Data.SQLite 库,但错误消息直接来自核心,没有其他异常属性可以帮助我.

I'm specifically using the System.Data.SQLite library for .NET but the error message comes directly from the core and there are no additional exception properties that could help me.

推荐答案

由于 SQLite 中实现延迟 FK 约束的方式,当出现错误时,此信息不可用.

Due to the way in which deferred FK constraints are implemented in SQLite, this information is not available when the error is raised.

您可以重新实现 FK 检查作为触发器.或者,记录失败命令中的值,然后手动查找数据.

You could reimplement the FK checks as triggers. Alternatively, log the values in the failed command, and look up the data by hand.

这篇关于明确知道 SQLite 中哪个 FOREIGN KEY 约束失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆