tortoise / tortoise/tortoise-orm
TextField as a PrimaryKey is Deprecated, use CharField instead
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
Sorry I'm not sure where I'd put this since it's not a feature request, not a bug and nor idea, just a question.
However pk for TextField generates following strange deprecation warning:
"TextField as a PrimaryKey is Deprecated, use CharField instead"
To Reproduce
Create a model field in Tortoise 0.17.6 with fields.TextField(pk=True)
Expected behavior
I would expect for this to work normally with no warning, since it still can be specified in the DB.
Additional context
I have an existing PostgreSQL DB that I just want to map with Tortoise into my python code for a special use case,
however in that DB there already is the primary key defined as a text field which is something you can easily do in PostgreSQL DB without any additional settings or length definitions.
So what do I do? Do I specify the field as the CharField() with some large value regardless? That doesn't seem right 🤔
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
No source file or test is named. Start by reproducing the warning with Tortoise 0.17.6 and fields.TextField(pk=True) against the described PostgreSQL schema, then trace where the deprecation is emitted. Done should establish the supported mapping for an existing text primary key and verify the resulting behavior with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100