我在过去之前已经在表中插入了很多行,但这个特定的实例一直给我一个错误,我无法弄清楚原因。我重新启动了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表是空的(我刚刚创建)
有关该怎么做的任何想法?谢谢。
答案 0 :(得分:4)
desc
是一个用于order by和whatnot
通过添加反引号魔术引号来逃避desc
:
insert into subreddits_subreddit(name, `desc`, admin_id)
values('firstSubreddit', 'This is a test.', 1)