0

I have two database in mysql running with innoDB and the second db has foreign key related to primary key of the first one.

In my code I need to insert in the first DB and get id for that and insert to the second one.

All goes well unless I start transaction and that locks the first DB for the new ID and second one cannot insert that ID and I am getting SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction. When I remove foreign key then it goes fine.

I need to mention that I use PHP PDO to connect to MySql and I create separate connection to each DB and I also cannot commit the first db transaction so that second one goes through because I need to make sure all transactions to all dbs goes fine in whole process and then start committing them.

Thanks Ramin

4

1 回答 1

0

似乎唯一的解决方案是提交第一个数据库并在第二个数据库上启动事务或删除数据库之间的外键。

如果您看到更好的解决方案,请提供解决方案,我会在将来的任何时候接受它作为答案。

谢谢拉明

于 2017-02-03T07:42:35.330 回答