Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL表未创建错误#1064_Mysql_Syntax_Foreign Keys_Mysql Error 1064 - Fatal编程技术网

MySQL表未创建错误#1064

MySQL表未创建错误#1064,mysql,syntax,foreign-keys,mysql-error-1064,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

以下是我的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
不幸的是,我在数据库编程方面的大部分经验都是在postgreSQL中,外键在那里似乎工作得更好

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

#1005 - Can't create table 'ourhoursdb.companyprinciple' (errno: 150)
这是完整的ddl.sql(…是其他列,但此表创建得很好)


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


另外,请确保您首先创建了具有
id
列的
user
表,列的类型与完全相同。

根据手册,没有“{”可写(),您是对的,但现在我明白了,#1005-无法创建表“ourhoursdb.companyprinciple”(错误号:150)再次检查我的答案。你们是先创建用户表的吗?好的,我知道了,我用的是SERIAL和INT,但它没有like@CraigDykstra:您没有id列为的用户表。我将在问题中添加完整的ddl.sql
CREATE TABLE companyprinciple (
  userid INT, 
  FOREIGN KEY (userid) REFERENCES user(id) ON DELETE CASCADE
) ENGINE=INNODB;
CREATE TABLE companyprinciple (
  userid INT, 
  FOREIGN KEY (userid) REFERENCES user(id) ON DELETE CASCADE
) ENGINE=INNODB;