Closed noahnu closed 2 years ago
That's right
Fixed
I tried adding a unique_together
composite index, and it did not detect the creation of the index, but it did detect the removal of said index.
I swapped the upgrade and downgrades lines in the generated migration file as a temporary workaround.
Before
class MyModel(Model):
id = fields.UUIDField(pk=True)
name = fields.CharField(max_length=255)
thing = fields.ForeignKeyField(
"models.SomeForeignTable", related_name="things", on_delete=fields.CASCADE, null=True
)
created_at = fields.DatetimeField(auto_now_add=True)
modified_at = fields.DatetimeField(auto_now=True)
After
class MyModel(Model):
id = fields.UUIDField(pk=True)
name = fields.CharField(max_length=255)
thing = fields.ForeignKeyField(
"models.SomeForeignTable", related_name="things", on_delete=fields.CASCADE, null=True
)
created_at = fields.DatetimeField(auto_now_add=True)
modified_at = fields.DatetimeField(auto_now=True)
class Meta:
indexes = (("thing_id", "name"),)
unique_together = (("thing_id", "name"),)
I'm using a postgreSQL database with tortoise orm.
The model:
Before:
After:
I then ran
aerich migrate --name default
and I'm getting a message "No changes detected". I've tried adding indexes to some other tables and it doesn't work. Constraints (i.e. unique_together) seems to work fine.