我使用以下SQL查询在WordPress数据库中创建一个表:
CREATE TABLE IF NOT EXISTS wp_ccwwhsh_sent_messages(
`id` INT NOT NULL AUTO_INCREMENT,
`timestamp` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`recipient_id` BIGINT NOT NULL,
`phone` VARCHAR(15) NOT NULL,
`content` TEXT NOT NULL,
`sending_confirm` DATETIME NULL,
PRIMARY KEY(`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
这是可行的。如果尝试创建链接到第一个表格的新表格,请使用:
CREATE TABLE IF NOT EXISTS wp_ccwwhsh_replies_to_messages(
`id` INT NOT NULL AUTO_INCREMENT,
`timestamp` DATETIME NOT NULL,
`message_id` BIGINT NOT NULL,
`content` TEXT NOT NULL,
PRIMARY KEY(`id`),
FOREIGN KEY(`message_id`) REFERENCES wp_ccwwhsh_sent_messages(`id`) ON DELETE CASCADE
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
我得到错误
#1005 - Impossible to create the table wordpress-dev.wp_ccwwhsh_replies_to_messages (errno: 150 "Foreign key constraint is incorrectly formed")
, 怎么了?