Fixes force to set ondelete=CASCADE in create_foreign_keys()

The create_foreign_keys method there forces any foreign keys that
created to have ondelete='CASCADE', no matter whether the
foreign_keys parameter passed to the method had that option set.
if the wrapper method remove_fks_from_table() is used to preserve
the state of foreign keys during a database migration, any foreign
keys on the table "perserved" this way will have cascading delete
added to them.

Change-Id: I04bdc863d67e2228f34a05f588c2e9f562918114
Closes-Bug: #1550027
This commit is contained in:
Zhengguang 2016-03-03 14:40:01 +08:00
parent 412012de59
commit 5ca8d0152a
2 changed files with 4 additions and 1 deletions

View File

@ -165,7 +165,7 @@ def create_foreign_keys(table, foreign_keys):
referent_table=fk['referred_table'],
local_cols=fk['constrained_columns'],
remote_cols=fk['referred_columns'],
ondelete='CASCADE'
ondelete=fk['options'].get('ondelete')
)

View File

@ -37,5 +37,8 @@ TABLE_NAME = 'flavorserviceprofilebindings'
def upgrade():
inspector = reflection.Inspector.from_engine(op.get_bind())
fk_constraints = inspector.get_foreign_keys(TABLE_NAME)
for fk in fk_constraints:
fk['options']['ondelete'] = 'CASCADE'
migration.remove_foreign_keys(TABLE_NAME, fk_constraints)
migration.create_foreign_keys(TABLE_NAME, fk_constraints)