我使用的是Alembic0.8.9,SQLAlchemy 1.1.4,我的数据库是MySQL数据库。
我正在更改一个表和一个外部列:
在我的数据库中,我将“器官”表重命名为“目的”。 使用
from alembic import op
def upgrade():
op.rename_table('organs', 'purposes')
之后,我想在另一个表中更新ForeignKey:
以前 在
^{pr2}$之后呢 在
class Order(DeclarativeBase):
__tablename__ = 'orders'
id = Column(Integer, autoincrement=True, primary_key=True)
purpose_id = Column(Integer, ForeignKey('purposes.id'))
我需要帮助编写一个Alembic迁移脚本,以反映在数据库中。如何更改ForeignKey列?在
谢谢你的帮助
感谢您的宝贵意见,让我对SQL外键进行了更多的搜索。我想我现在明白了。
这个答案给我指明了方向:
How to change the foreign key referential action? (behavior)
基本上,我需要做的是重命名列(保存数据),删除旧的外键(约束?)然后创造一个新的。在
以下是我的迁移脚本:
相关问题 更多 >
编程相关推荐