Mysql 用于创建外键的正确语法

Mysql 用于创建外键的正确语法,mysql,sql,phpmyadmin,Mysql,Sql,Phpmyadmin,我使用的是MySQL5.5.8,但我不知道该如何编写需要外键引用的字段。例如: CREATE TABLE IF NOT EXISTS `answers` ( `id` int( 11 ) NOT NULL AUTO_INCREMENT , `answer` text COLLATE utf8_polish_ci NOT NULL , `user` tinyint( 4 ) DEFAULT NULL , `created` timestamp NULL DEFAULT CURRENT_TIMEST

我使用的是MySQL5.5.8,但我不知道该如何编写需要外键引用的字段。例如:

CREATE TABLE IF NOT EXISTS `answers` (
`id` int( 11 ) NOT NULL AUTO_INCREMENT ,
`answer` text COLLATE utf8_polish_ci NOT NULL ,
`user` tinyint( 4 ) DEFAULT NULL ,
`created` timestamp NULL DEFAULT CURRENT_TIMESTAMP ,
`html_template_id` int( 11 ) NOT NULL ,
PRIMARY KEY ( `id` ) ,
CONSTRAINT html_template_id FOREIGN KEY `html_template_id` REFERENCES `html_templates` ( `id` )
) ENGINE = InnoDB DEFAULT CHARSET = utf8 COLLATE = utf8_polish_ci AUTO_INCREMENT =1;
我收到一条错误消息:

 #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'REFERENCES `html_templates`(`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=' at line 10
使用

i、 e.外键字段应在括号中

CONSTRAINT html_template_id FOREIGN KEY (`html_template_id`) REFERENCES `html_templates` ( `id` )