mysql: key reference and table reference do not match
P粉798010441
P粉798010441 2023-07-18 15:17:02
0
1
483

error message:

SQLSTATE[42000]: Syntax error or access violation: 1239 Incorrect foreign key definition for 'fk.faq.product_id': Key reference and table reference don't match

Product List:

CREATE TABLE `product` (
    `id` BINARY(16) NOT NULL,
    `version_id` BINARY(16) NOT NULL,
    `created_at` DATETIME(3) NOT NULL,
    `updated_at` DATETIME(3) NULL,
    PRIMARY KEY (`id`,`version_id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

FAQ:

CREATE TABLE `faq` (
    `id` BINARY(16) NOT NULL,
    `question` VARCHAR(255) NULL,
    `answer` VARCHAR(255) NULL,
    `product_id` BINARY(16) NOT NULL,
    `created_at` DATETIME(3) NOT NULL,
    `updated_at` DATETIME(3) NULL,
    PRIMARY KEY (`id`),
    KEY `fk.faq.product_id` (`product_id`),
    CONSTRAINT `fk.faq.product_id` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`,`version_id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

I created a FAQ table to combine with the products table, but it keeps getting errors and I can't find where the questions in the table go wrong. Thanks for the help.

P粉798010441
P粉798010441

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!