Flask Migrate ondelete级联不起作用

时间:2018-08-09 21:35:14

标签: flask sqlalchemy flask-sqlalchemy flask-migrate sqlalchemy-migrate

我正在使用烧瓶迁移在MySQL数据库中创建表。删除资产或培训数据条目时,我希望删除assets_training_data_xref条目。运行迁移时,生成的SQL表没有“ ON DELETE CASCADE”。我究竟做错了什么?我不打算使用SQLAlchemy代码更新表(只是原始SQL)是问题吗?

这是我的桌子:

class Assets(db.Model):
    __tablename__ = "assets"
    asset_id = db.Column(db.Integer, primary_key=True)
    asset_name = db.Column(db.String(150), unique=True, nullable=False)
    asset_desc = db.Column(db.Text)

class Training_Data(db.Model):
    __tablename__ = "training_data"
    train_id = db.Column(db.BigInteger, primary_key=True)
    train_desc = db.Column(db.Text)
    train_classification = db.Column(db.Text)
    train_updated = db.Column(db.TIMESTAMP, onupdate=func.utc_timestamp())

class Assets_Training_Data_Xref(db.Model):
    __tablename__ = "assets_training_data_xref"
    fk_asset_id = db.Column(db.ForeignKey("assets.asset_id", 
        ondelete="CASCADE"), primary_key=True, index=True)
    fk_train_id = db.Column(db.ForeignKey("training_data.train_id", 
        ondelete="CASCADE"), primary_key=True, index=True)

0 个答案:

没有答案