tortoise / tortoise/tortoise-orm
Constraints defined within Meta are not applied when performing data migrations.
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
Constraints are defined in the Meta class of the data model, and the native Tortoise migration tool is used to perform data migration. However, the constraints are not created as expected in the resulting database table.
To Reproduce
class Like(Model):
id = IntField(primary_key=True)
types = CharField(default='news', max_length=10)
user_id = IntField(default=0)
art_id = IntField(default=0)
class Meta:
table = 'like'
constraints = [UniqueConstraint(fields=('types', 'user_id', 'art_id'), name='unique_like')]
*The Tortoise‑ORM version is 1.1.8
Expected behavior
A unique index named unique_like was supposed to be created in the database, but nothing appears in the database.
There are no exceptions or error hints during data migration.
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 the native Tortoise migration tool's handling of constraints declared in a model's Meta class, using the Like model and its unique_like constraint as the reproduction. Run a data migration against the supported database setup and verify that the resulting like table contains the expected unique index without errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100