MySQL表没有创建错误#1064

时间:2012-03-31 05:31:02

标签: mysql syntax foreign-keys mysql-error-1064

这是我的sql:

CREATE TABLE companyprinciple {
userid INT, 
FOREIGN KEY (userid) REFERENCES user(id) ON DELETE CASCADE
}ENGINE=INNODB;

这是我得到的错误:

#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 '{
userid INT, 
FOREIGN KEY (userid) REFERENCES user(id) ON DELETE CASCADE
}ENG' at line 1

遗憾的是,我在db编程方面的大多数经验都是在postgreSQL中,外键在它看起来效果要好得多。

编辑:好吧所以第一个问题是我的眼睛闭上了,而{}应该是()但是现在我得到了一个新的错误

#1005 - Can't create table 'ourhoursdb.companyprinciple' (errno: 150)

这里是完整的ddl.sql(...是其他列,但这个表创建正常)

CREATE SCHEMA OurHoursDB;
USE OurHoursDB;

CREATE TABLE User (
id SERIAL NOT NULL PRIMARY KEY,
...

) ENGINE=INNODB;

CREATE TABLE companyprinciple (
userid INT, 
FOREIGN KEY (userid) REFERENCES user(id) ON DELETE CASCADE
)ENGINE=INNODB;

2 个答案:

答案 0 :(得分:0)

使用圆括号对()卷曲的{}

另外,请确保您已创建user表格,其中id列首先完全相同类型

答案 1 :(得分:0)

CREATE TABLE companyprinciple (
  userid INT, 
  FOREIGN KEY (userid) REFERENCES user(id) ON DELETE CASCADE
) ENGINE=INNODB;