tortoise / aerich

A database migrations tool for TortoiseORM, ready to production.
https://github.com/tortoise/aerich
Apache License 2.0
820 stars 94 forks source link

Invalid generating INDEX name of tables in migrations #195

Open pankoffDaniel opened 2 years ago

pankoffDaniel commented 2 years ago

The problem happens when we change UNIQUE parameter in table field and launch migration.

Detail problem is below.

models.py

class Genre(Model):
    name = fields.CharField(max_length=255, unique=True)

    def __str__(self):
        return self.name
  1. aerich init-db

PostgreSQL UNIQUE index is True

  1. Change UNIQUE parameter models.py
  2. aerich migrate generates this SQL:
-- upgrade --
DROP INDEX "idx_genre_name_c78cd9";
-- downgrade --
CREATE UNIQUE INDEX "uid_genre_name_c78cd9" ON "genre" ("name");
  1. aerich upgrade raises an error:
tortoise.exceptions.OperationalError: index "idx_genre_name_c78cd9" does not exist
madwayz commented 2 years ago

Удали.