From 5a28a07b10c4f7fef2046c4e84929706c8351e19 Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Thu, 15 Dec 2011 21:54:07 +0100 Subject: [PATCH] Ensure fkey is dropped before removing instance_id This fixes Bug #904888 On MySQL databases that use InnoDB by default (ie, at the point when database is being first migrated), extra care needs to be taken to ensure FKs are dropped before columns because they are not automatically. Patch from Adam Gandelman and Scott Moser. Change-Id: I32919a46bb76f524e064098738ad98248b2f1c0e --- .../064_change_instance_id_to_uuid_in_instance_actions.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nova/db/sqlalchemy/migrate_repo/versions/064_change_instance_id_to_uuid_in_instance_actions.py b/nova/db/sqlalchemy/migrate_repo/versions/064_change_instance_id_to_uuid_in_instance_actions.py index df9d7302804c..a10ae11fcf7e 100644 --- a/nova/db/sqlalchemy/migrate_repo/versions/064_change_instance_id_to_uuid_in_instance_actions.py +++ b/nova/db/sqlalchemy/migrate_repo/versions/064_change_instance_id_to_uuid_in_instance_actions.py @@ -48,6 +48,13 @@ def upgrade(migrate_engine): uuid_column.drop() raise + if migrate_engine.name == "mysql": + try: + migrate_engine.execute("ALTER TABLE instance_actions " \ + "DROP FOREIGN KEY instance_actions_ibfk_1;") + except Exception: # Don't care, just fail silently. + pass + instance_actions.c.instance_id.drop()