最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

mariadb - Cannot delete or update a parent row: a foreign key constraint fails with Galera and MaxScale - Stack Overflow

matteradmin7PV0评论

I'm working with two servers MariaDB with galera replication and MaxScale rw router.
One server takes write queryies only, the other one just selects.

I have this sequence of operations:

  • start transaction with propagation REQUIRES_NEW and isolation READ_COMMITTED
  • insert new record in tableA and get ID
  • insert new record in tableB using previous inserted ID as foreign key to tableA
  • commit
  • fails with Error: 1451-23000: Cannot delete or update a parent row: a foreign key constraint fails

This is not a systematics issue; most times it works without error, but a few times it fails. It may be connected to replication; that answers why most times it works and why the issue is thrown after the commit.

What I'm missing?

The issue doesn't arise from the master-write database because it is the database of the first tableA insertion. It is more likely the issue comes from the second server at replication time.

But since the transaction is unique and the replication works by entire transactions, how is it possibile that the foreign key doesn't work?

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far