mysql 在删除级联上不起作用

发布于 2024-08-27 15:12:12 字数 597 浏览 3 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

糖粟与秋泊 2024-09-03 15:12:12

好的,找到解决方案了。我必须像这样指定 innodb 的类型:

CREATE TABLE sometable
(
testId CHAR(43),
blocked BOOL,
PRIMARY KEY(testId)
) type=innodb;

谢谢您的评论

// Jakob

Ok, found the solution. I had to specify the type to innodb like this:

CREATE TABLE sometable
(
testId CHAR(43),
blocked BOOL,
PRIMARY KEY(testId)
) type=innodb;

Thank you for the comments

// Jakob

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文