aerich
aerich copied to clipboard
PostgreSQL does not allow dropping unique indexes via DROP INDEX
If a migration containing a "DROP INDEX" command with a unique index is executed on PostgreSQL, an error is raised, claiming
asyncpg.exceptions.DependentObjectsStillExistError: cannot drop index uid_imagetempla_guild_i_25a69e because constraint uid_imagetempla_guild_i_25a69e on table imagetemplate requires it
HINT: You can drop constraint uid_imagetempla_guild_i_25a69e on table imagetemplate instead.
I had to modify the original SQL to this:
async def upgrade(db: BaseDBAsyncClient) -> str:
return """
CREATE UNIQUE INDEX "uid_statistic_channel_f53e9b" ON "statistic" ("channel_id", "thread_id", "author_id", "month");
ALTER TABLE "statistic" DROP CONSTRAINT "uid_statistic_channel_3743df";"""
async def downgrade(db: BaseDBAsyncClient) -> str:
return """
ALTER TABLE "statistic" ADD CONSTRAINT "uid_statistic_channel_3743df" UNIQUE ("channel_id", "thread_id", "author_id");
DROP INDEX "uid_statistic_channel_f53e9b";"""