phpMyAdmin:即使类型相同,也无法设置特定的外键
我的 list_items 表具有以下列
- `ListID`
- `WordID`
我的列表表有一个自动递增的主键 `ListID`。我想让 list_items 中的“ListID”成为引用列表中主键的外键,但出现错误:
在“ListID”上创建外键时出错(检查数据类型)。
两列都是 int(8),并且两个表类型都是 InnoDB。可能是什么问题?
遵循这些说明在设置其他外键方面效果很好。
我唯一能想到的是在 phpMyAdmin 的主屏幕上,有一条消息:
“用于处理链接表的附加功能已被停用。要了解原因,请单击此处。”
但是那里的任何问题不会阻止我设置其他外键吗?
相关SQL:
--
-- Table structure for table `lists`
--
CREATE TABLE IF NOT EXISTS `lists` (
```ListID``` int(8) NOT NULL AUTO_INCREMENT,
```UserID``` int(8) NOT NULL,
```privacy``` varchar(25) NOT NULL,
```name``` varchar(50) NOT NULL,
```description``` text NOT NULL,
```date created``` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
```date modified``` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (```ListID```),
KEY ```UserID``` (```UserID```)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `lists`
--
--
-- Table structure for table `list_items`
--
CREATE TABLE IF NOT EXISTS `list_items` (
```ListID``` int(8) NOT NULL,
```WordID``` int(8) NOT NULL,
KEY ```ListID``` (```ListID```),
KEY ```WordID``` (```WordID```)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `list_items`
--
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
```UserID``` int(8) NOT NULL AUTO_INCREMENT,
```email``` int(50) NOT NULL,
```username``` int(25) NOT NULL,
```password``` int(25) NOT NULL,
```join date``` int(11) NOT NULL,
PRIMARY KEY (```UserID```)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
My list_items table has the following columns
- `ListID`
- `WordID`
My lists table has a primary, auto-incremented primary key `ListID`. I want to make the `ListID` in list_items a foreign key referencing the primary key in lists, but I get an error:
Error creating foreign key on `ListID` (check data types).
Both columns are int(8), and both table types are InnoDB. What could possibly be the issue?
Following these instructions has worked fine in setting up other foreign keys.
The only thing I can think of is on phpMyAdmin's main screen, there's a message:
"The additional features for working with linked tables have been deactivated. To find out why click here."
But wouldn't any issue there prevent me from setting up other foreign keys?
Relevant SQL:
--
-- Table structure for table `lists`
--
CREATE TABLE IF NOT EXISTS `lists` (
```ListID``` int(8) NOT NULL AUTO_INCREMENT,
```UserID``` int(8) NOT NULL,
```privacy``` varchar(25) NOT NULL,
```name``` varchar(50) NOT NULL,
```description``` text NOT NULL,
```date created``` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
```date modified``` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (```ListID```),
KEY ```UserID``` (```UserID```)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `lists`
--
--
-- Table structure for table `list_items`
--
CREATE TABLE IF NOT EXISTS `list_items` (
```ListID``` int(8) NOT NULL,
```WordID``` int(8) NOT NULL,
KEY ```ListID``` (```ListID```),
KEY ```WordID``` (```WordID```)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `list_items`
--
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
```UserID``` int(8) NOT NULL AUTO_INCREMENT,
```email``` int(50) NOT NULL,
```username``` int(25) NOT NULL,
```password``` int(25) NOT NULL,
```join date``` int(11) NOT NULL,
PRIMARY KEY (```UserID```)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的sql中有很多反引号
通常你只有一套,这可能会导致问题
示例
you have an awful lot of backticks in your sql
normally you would only have 1 set, that could be causing a problem
example
我手动尝试了一下,下面的外键创建得很好
I tried it manually with this the below at the foreign key was created fine