diff --git a/frappe/database/utils.py b/frappe/database/utils.py index 3165046faf..0247d9fce4 100644 --- a/frappe/database/utils.py +++ b/frappe/database/utils.py @@ -193,7 +193,12 @@ def drop_index_if_exists(table: str, index: str): return try: - frappe.db.sql_ddl(f"ALTER TABLE `{table}` DROP INDEX `{index}`") + if frappe.db.db_type == "postgres": + # Postgres drops indexes with DROP INDEX, not ALTER TABLE ... DROP INDEX + safe_index = index.replace('"', '""') + frappe.db.sql_ddl(f'DROP INDEX IF EXISTS "{safe_index}"') + else: + frappe.db.sql_ddl(f"ALTER TABLE `{table}` DROP INDEX `{index}`") except Exception as e: frappe.log_error("Failed to drop index") click.secho(f"x Failed to drop index {index} from {table}\n {e!s}", fg="red")