gpt4 book ai didi

mysql - 无法添加或更新子行 : a foreign key constraint fails in MySQL

转载 作者:行者123 更新时间:2023-11-29 05:26:57 25 4
gpt4 key购买 nike

我有两个相互关联的表。当它尝试插入时,我收到错误消息:

Cannot add or update a child row: a foreign key constraint fails (Token, CONSTRAINT FK_Token_my_aspnet_users_id FOREIGN KEY (UserId) REFERENCES my_aspnet_users (id) ON DELETE NO ACTION ON UPDATE NO ACTION)

这是两个表的脚本:

token

CREATE TABLE Token (
Id INT(11) NOT NULL AUTO_INCREMENT,
UserId INT(11) NOT NULL,
Token CHAR(36) NOT NULL,
PRIMARY KEY (Id),
CONSTRAINT FK_Token_my_aspnet_users_id FOREIGN KEY (UserId)
REFERENCES my_aspnet_users(id) ON DELETE NO ACTION ON UPDATE NO ACTION
)
ENGINE = INNODB
AUTO_INCREMENT = 7
CHARACTER SET latin1
COLLATE latin1_swedish_ci;

my_aspnet_users

CREATE TABLE my_aspnet_users (
id INT(11) NOT NULL AUTO_INCREMENT,
applicationId INT(11) NOT NULL,
name VARCHAR(256) NOT NULL,
isAnonymous TINYINT(1) NOT NULL DEFAULT 1,
lastActivityDate DATETIME DEFAULT NULL,
PRIMARY KEY (id),
INDEX fk_users_applications_idx (applicationId),
CONSTRAINT fk_users_applications FOREIGN KEY (applicationId)
REFERENCES my_aspnet_applications(id) ON DELETE NO ACTION ON UPDATE NO ACTION
)
ENGINE = INNODB
AUTO_INCREMENT = 364
AVG_ROW_LENGTH = 83
CHARACTER SET latin1
COLLATE latin1_swedish_ci;

最佳答案

验证您尝试插入的 token ID 是否确实存在

关于mysql - 无法添加或更新子行 : a foreign key constraint fails in MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19098713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com