mysql 在删除级联上不起作用
我正在尝试在 mysql 数据库中使用 ON CASCADE DELETE 但无法使其工作。 这是我的代码:
CREATE TABLE sometable
(
testId CHAR(43),
blocked BOOL,
PRIMARY KEY(testId)
);
CREATE TABLE p
(
testId CHAR(43),
phrase text,
source text,
FOREIGN KEY (testId) REFERENCES sometable (testId) on delete cascade
);
CREATE TRIGGER sometable_insert BEFORE INSERT ON `sometable` FOR EACH ROW SET NEW.`testId` =UUID();
然后我执行插入到某个表中,这将生成一个 UUID。 我获取这个 UUID 并将其插入到表 p 中。 插入 p(testId,phrase,source)values('07616f60-424f-11df-871a-b98e9', 'fun', 'test');
当对某个表中的行进行删除时,表 p 中没有任何反应。 我错过了什么或者我做错了什么
I'm trying to use ON CASCADE DELETE in mysql db but I can't make it work.
Here is my code:
CREATE TABLE sometable
(
testId CHAR(43),
blocked BOOL,
PRIMARY KEY(testId)
);
CREATE TABLE p
(
testId CHAR(43),
phrase text,
source text,
FOREIGN KEY (testId) REFERENCES sometable (testId) on delete cascade
);
CREATE TRIGGER sometable_insert BEFORE INSERT ON `sometable` FOR EACH ROW SET NEW.`testId` =UUID();
I then perform an insert into sometable, which will generate a UUID.
I take this UUID and insert it to table p.
insert into p(testId, phrase, source) values('07616f60-424f-11df-871a-b98e9', 'fun', 'test');
When doing a delete on the row in sometable nothing happens in table p.
What have i missed or what I'm i doing wrong
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,找到解决方案了。我必须像这样指定 innodb 的类型:
谢谢您的评论
// Jakob
Ok, found the solution. I had to specify the type to innodb like this:
Thank you for the comments
// Jakob