php - PHP 没有设置 FOREIGN 键
问题描述
再会,
我面临一个谜,我想通过PHP在数据库中导入以下内容。
$sql = "
CREATE TABLE IF NOT EXISTS `whtsdg_field_products`
(
`whtsdg_field_products_id` int(11) NOT NULL auto_increment,
`whtsdg_field_list_id` int(11) unsigned NOT NULL,
`product_number` varchar(255) NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (whtsdg_field_products_id),
FOREIGN KEY (whtsdg_field_list_id) REFERENCES whtsdg_field_list (whtsdg_field_list_id)
);";
$db->executeQuery($sql);
到目前为止,这一切都有效,只是他没有给我设置 FK,我不知道为什么。如果我在 MySQL 中输入代码,那么一切正常。有人可以告诉我我做错了什么或错误在哪里吗?
编辑:我使用“SELECT table_name,table_schema FROM information_schema.tables WHERE engine = 'InnoDB'”检查了表,因此存储引擎似乎是InnoDB。我的表的架构是:
whtsdg_config_list
whtsdg_config_list_id int(11) noNULL noStandard AUTO_INCREMENT Primarykey Unique whtsdg_fiel_list_id int(11) noNULL noStandard >应该是一个 FK< Unique whtsdg_fiel_config_id int(11) noNULL noStandard >应该是一个 FK< Unique created_at timestamp attribute="on update CURRENT_TIMESTAMP" NULLallowd标准=CURRENT_TIMESTAMP 额外="ON UPDATE CURRENT_TIMESTAMP"
whtsdg_field_config
whtsdg_field_config_id int(11) noNUL noStandard AUTO_INCREMENT Primarykey 唯一名称 varchar(255)utf8_general_ci noNULL noStandard config json noNULL noStandard created_at timestamp attribute="on update CURRENT_TIMESTAMP" NULLallowd standard=CURRENT_TIMESTAMP extra="ON UPDATE CURRENT_TIMESTAMP"
whtsdg_field_list
whtsdg_field_list_id int(11) noNUL noStandard AUTO_INCREMENT Primarykey Unique Setname varchar(255)utf8_general_ci noNULL noStandard created_at timestamp attribute="on update CURRENT_TIMESTAMP" NULLallowd standard=CURRENT_TIMESTAMP extra="ON UPDATE CURRENT_TIMESTAMP"
whtsdg_field_proudcts
whtsdg_field_proudcts_id int(11) noNUL noStandard AUTO_INCREMENT Primarykey Unique whtsdg_field_list_id int(11) noNULL noStandard >应该是一个 FK< Unique product_number varchar(255)utf8_general_ci noNULL noStandard created_at timestamp attribute="on update CURRENT_TIMESTAMP" NULLallowd standard=CURRENT_TIMESTAMP extraON更新 CURRENT_TIMESTAMP”
解决方案
推荐阅读
- amazon-web-services - DynamoDB 查询 3 个字段
- javascript - 在遵守 Eslint no-param-reassign 的同时从对象中删除
- django - 在 django 上覆盖不同表中的字段
- java - 如何在 Mulesoft 4 自定义连接器中使用非阻塞 HTTP 请求
- reactjs - 如何在 React 中使用 Map 遍历复杂对象
- amazon-alb - Amazon ALB:如何在没有自定义域的情况下设置 HTTPS 侦听器
- javascript - 'string | 类型不存在属性'substr' 细绳[]'
- php - 您可以将 acf 子字段循环到 html 标记中吗?
- php - 少数参数的依赖注入
- angularjs - 内容下载(CSS、JS 等)花费太多时间,导致加载速度太慢