tortoise / tortoise/tortoise-orm
BinaryField failing unique constraint SQLite
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with BinaryField handling for the SQLite dialect and reproduce the issue using the Example model shown in the report. Verify that a BinaryField with unique=True is accepted, the schema includes BLOB NOT NULL UNIQUE, and inserting duplicate bytes raises a uniqueness error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sqlite
- Domain
- database
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100