def rename_link_table(self):
old_table_name = 'requirement_deferred_actions__deferredaction_requirements'
new_table_name = 'deferredaction_requirement'
# Rename table itself
self.schedule('alter', op.rename_table, old_table_name, new_table_name)
# Rename of foreign key names
for old_name, other_table_name in [
('deferredaction_requirements_fk', 'deferredaction'),
('requirement_deferred_actions_fk', 'requirement') ]:
column_name = '%s_id' % other_table_name
new_name = fk_name(new_table_name, column_name, other_table_name)
self.schedule('drop_fk', op.drop_constraint, old_name, old_table_name)
self.schedule('create_fk', op.create_foreign_key, new_name, new_table_name, other_table_name, [column_name], ['id'])
# Primary keys are renamed according to new naming convention - in this case the table too
self.rename_pk(new_table_name, ['deferredaction_id', 'requirement_id'], old_table_name=old_table_name)
评论列表
文章目录