过去,我已经在表中插入了很多行,但是这个特定的实例不断给我一个错误,我不知道为什么。我已经重新启动mysql /尝试禁用外键检查等,但仍然失败。
这是我的插入命令:
insert into subreddits_subreddit(name, desc, admin_id) values('firstSubreddit',
'This is a test.', 1)
我的错误:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that c
orresponds to your MySQL server version for the right syntax to use near 'desc, admin_id)
values('firstSubreddit', 'This is a test.', 1)' at line 1
这是subreddits_subreddit的架构。
subreddits_subreddit | CREATE TABLE `subreddits_subreddit` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) DEFAULT NULL,
`desc` varchar(3000) DEFAULT NULL,
`admin_id` int(11) DEFAULT NULL,
`created_on` datetime DEFAULT NULL,
`updated_on` datetime DEFAULT NULL,
`status` smallint(6) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`),
KEY `user_id` (`admin_id`),
CONSTRAINT `subreddits_subreddit_ibfk_1` FOREIGN KEY (`admin_id`) REFERENCES
`users_user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
这是它引用的用户表:
users_user | CREATE TABLE `users_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(80) DEFAULT NULL,
`email` varchar(200) DEFAULT NULL,
`password` varchar(200) DEFAULT NULL,
`created_on` datetime DEFAULT NULL,
`status` smallint(6) DEFAULT NULL,
`role` smallint(6) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 |
users_user表中有一行,其id值为1,因此用户FK引用应该可以。subreddits_subreddit表为空(我刚刚做了)
有什么想法做什么?谢谢你。
desc
是与order by和whatnot一起使用的关键字
逃生desc
通过把反引号魔术引号:
insert into subreddits_subreddit(name, `desc`, admin_id)
values('firstSubreddit', 'This is a test.', 1)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句