BinaryField failing unique constraint SQLite

未关闭 适合新手
#668 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
65/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python, sqlite
领域
database

调研方向

从 SQLite 方言的 BinaryField 处理开始,并使用报告中所示的 Example 模型重现该问题。验证带有 unique=True 的 BinaryField 能被接受,schema 包含 BLOB NOT NULL UNIQUE,并且插入重复字节会引发唯一性错误。

由索引模型根据 Issue 内容生成。

描述

Describe the bug
When trying to implement a UNIQUE constraint on a BinaryField, the program raised a ConfigurationError indicating that the field could not be indexed. SQLite does support UNIQUE constraints on a Binary or BLOB field.

To Reproduce

class Example(models.Model):
    id = fields.UUIDField(pk=True)
    binary = fields.BinaryField(unique=True, null=False)

When adding this model, you'll get tortoise.exceptions.ConfigurationError: BinaryField can't be indexed.

CREATE TABLE Example(
    id CHAR(36) NOT NULL PRIMARY KEY,
    binary BLOB NOT NULL UNIQUE
);

This will work perfectly on SQLite. .schema Example returns the correct schema and inserting data will work and raise an error when duplicate bytes are inserted.

Expected behavior
I would like to see the removal of indexable = False on SQLite Binary fields, as it is supported by the dialect.

主要语言
Python
星标
5.6k
派生
543
平均合并
4 天 7 小时
30 天内合并 PR
31

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

tortoise/tortoise-orm 的其他 Issue

查看 tortoise/tortoise-orm 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。