简体   繁体   English

MYSQL外键未更新表

[英]MYSQL Foreign Key not Updating Table

Table 1: 表格1:

+--------------+-------------+------+-----+---------+----------------+
| Field        | Type        | Null | Key | Default | Extra          |
+--------------+-------------+------+-----+---------+----------------+
| ID           | int(11)     | NO   | PRI | NULL    | auto_increment |
| FONO         | int(11)     | NO   | MUL |         |                |
| Description  | varchar(25) | NO   |     |         |                |
| Amount       | varchar(60) | NO   |     |         |                |
+--------------+-------------+------+-----+---------+----------------+

Table 2: 表2:

+--------------+-------------+------+-----+---------+----------------+
| Field        | Type        | Null | Key | Default | Extra          |
+--------------+-------------+------+-----+---------+----------------+
| FONO         | int(11)     | NO   | PRI | NULL    | auto_increment |
| FINVNO       | varchar(20) | NO   |     |         |                |
| Description  | varchar(25) | NO   |     |         |                |
| Amount       | varchar(60) | NO   |     |         |                |
+--------------+-------------+------+-----+---------+----------------+

I would like the Column FONO in table 1 automatically get the value from the FONO column in table 2. I have set it up so that on update it cascades. 我希望表1中的FONO列自动从表2中的FONO列获取值。我对其进行了设置,以便在更新时可以级联。

Although when the records are being entered the FONO column in table 1 remains empty. 尽管在输入记录时,表1中的FONO列仍为空。

Why is this happening? 为什么会这样呢? What can I do to solve this? 我该怎么解决?

Thank You. 谢谢。

Cascade happen on deleting and update the primary key that in which its foreign key is defined with cascade behavior and not insertion. 级联发生在删除和更新主键时,该主键的外键是通过级联行为而不是插入操作定义的。

ON DELETE CASCADE

ON UPDATE CASCADE

Just check out more here 只是在这里查看更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM