外键自动增量在 sqlite .NET 提供程序中不起作用

发布于 2024-12-06 17:04:43 字数 432 浏览 0 评论 0原文

我将多个数据插入到 sqlite 表中,并始终获得相同的 ID。但字段Id配置为PK+autoinc Id。

我使用它作为连接字符串:

public static void SetConnectionString(string dataDataAccessPath)
        {
            _connectionString = String.Format(@"Data Source={0};Foreign Keys=ON", dataDataAccessPath);
        }

除了“PRAGMAforeign_keys = ON;”之外,还为连接实现了“Foreign Keys=ON”必须为每个打开的连接执行该操作。

现在我想知道为什么连接字符串上的新属性不起作用......

我有什么问题吗?

I insert multiple data into a sqlite table and get always the same ID back. But the field Id is configured as PK + autoinc Id.

I use this as connection string:

public static void SetConnectionString(string dataDataAccessPath)
        {
            _connectionString = String.Format(@"Data Source={0};Foreign Keys=ON", dataDataAccessPath);
        }

This "Foreign Keys=ON" was implemented for the connection besides the "PRAGMA foreign_keys = ON;" which had to be executed for every opened connection.

Now I wonder why the new attribute on the connectionstring does not work...

Do I something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热血少△年 2024-12-13 17:04:43

我不是 SQLite 方面的专家(事实上我没有实践经验),但我想你的 IDENTITY 字段是否会随着插入而自动增加与定义有更多关系表的内容与您正在使用的连接字符串的内容相比。

请注意,您本身无法增加FOREIGN KEY,而是需要使用充当PRIMARY KEYIDENTITY字段来增加表> 然后 FOREIGN KEY 引用。

您可以添加您遇到问题的表的定义吗?

I'm not an expert on SQLite (in fact I have no practical experience with it) but I would imagine that whether or not your IDENTITY fields automatically increment with your insert has something to do more with the definition of the table than with the connection string you are using.

Be reminded that you cannot increment a FOREIGN KEY per se, but rather you need to increment the table with the IDENTITY field that serves as the PRIMARY KEY that the FOREIGN KEY then references.

Can you add the definition of the table that you are having trouble with?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文