相关文章推荐
睿智的弓箭  ·  Spring ...·  1 年前    · 
幸福的番茄  ·  What's New in TiDB ...·  1 年前    · 
非常酷的冲锋衣  ·  groovy no such ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm using Flask-SQLAlchemy with a MySQL database using the InnoDB engine which does support ondelete and onupdate.

I have the following in my 'Posts' table which refers to an Accounts table:

account_id = db.Column(db.Integer, db.ForeignKey('accounts.id', onupdate="CASCADE", ondelete="CASCADE"))

I updated the database using Flask-Migrate (Alembic) and I've noticed that the onupdate and ondelete values are not changed when I specify onupdate="CASCADE", ondelete="CASCADE" even though it states I should use it like this in the SQLAlchemy Documentation

What could be the issue? Thanks.

The reason the ondelete and onupdate values don't update is because they cannot be changed when there is already that foreign key present.

To change it, I had to remove the foreign key from the table, update the database and then re-add it to the table with the values you want then update once again.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.