插入到具有外部约束的 UUID 列失败

Insert to an UUID column with a foreign constraint fails

我有以下 table 结构和数据:

votes table

season | episode | UUID    | vote
1      | 1       | X-X-X-X | 1
1      | 1       | Y-Y-Y-Y | -1

users table

UUID    | name
X-X-X-X | Jon
Y-Y-Y-Y | Sam
Z-Z-Z-Z | Tim

votestable之后运行

ALTER TABLE votes ADD PRIMARY KEY (season, episode, UUID);
ALTER TABLE votes ADD INDEX (UUID);
ALTER TABLE votes ADD FOREIGN KEY (UUID) REFERENCES user (UUID)
                           ON DELETE CASCADE ON UPDATE CASCADE;

并尝试插入这样的条目:

season, episode, UUID,      vote
1,      1,       'Z-Z-Z-Z', 1

进入说table,迎接我的是如下错误:

Cannot add or update a child row: a foreign key constraint fails (voting, CONSTRAINT `constraint_name` FOREIGN KEY (UUID) REFERENCES users (UUID) ON DELETE CASCADE ON UPDATE CASCADE)

我想让 UUID 与 users table 保持联系,同时不允许每个同一季 - 剧集 - UUID 组合多次投票,我该如何实现?

问题是我使用 phpMyAdmin 的“插入”选项卡添加数据,它自动从“功能”下拉列表中选择 UUID,这改变了我想要插入的数据。将下拉列表设置为空值,只留下我插入的值,添加就很好了。