tortoise / tortoise/tortoise-orm
Composite primary keys
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Is your feature request related to a problem? Please describe.
I must create a table where the primary key is a composite of fields, but this is not supported. Excerpt from the docs:
We currently support single (non-composite) primary keys of any indexable field type
Describe the solution you'd like
A model like:
class Mutation(BaseDatasetTag):
gene: str = fields.CharField(pk=True, max_length=80)
knock_out: bool = fields.BooleanField(pk=True, default=False)
knock_in: bool = fields.BooleanField(pk=True, default=False)
method: str = fields.CharField(pk=True, max_length=200)
Describe alternatives you've considered
There are none, but worse alternatives to this implementation of the table. I will have to use a UUID field, and I will have to filter every time I want to be certain the combinations of field values doesn't exist in my DB.
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
The issue provides a proposed Mutation model with multiple fields marked as primary keys, but names no implementation files or tests. Start by tracing how model primary keys and schema generation are handled, then define completion as supporting the requested composite-key model without requiring a separate UUID field and covering the behavior with tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100