def change_inheriting_table(self, table_name, old_id_column_name, parent_table_name):
"""Tables of classes that inherit from other classes (using joint table inheritance) named their
primary key columns xxx_id (assuming the parent is called xxx here). These were also foreign
keys to the primary key of the parent table. In our Declarative implementation we just always use
the name `id` for a primary key regardless of the situation.
This method renames such primary key columns, and deal with the knock-on effect of this change
to related primary and foreign key as well.
:arg table_name: The name of the table underlying the child/inheriting class.
:arg old_id_column_name: The old name of the primary key column of the child/inheriting class.
:arg parent_table_name: The name of the table underlying the parent class.
"""
self.schedule('drop_fk', op.drop_constraint, '%s_%s_fkey' % (table_name, old_id_column_name), table_name)
self.rename_pk_column(table_name, old_id_column_name, 'id', ['id'])
self.schedule('create_fk', op.create_foreign_key, fk_name(table_name, 'id', parent_table_name), table_name,
parent_table_name, ['id'], ['id'], ondelete='CASCADE')
评论列表
文章目录