简体   繁体   English

MySQL表未创建错误#1064

[英]MySQL table not creating error #1064

Here is my sql: 这是我的SQL:

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

and here is the error that I am getting: 这是我得到的错误:

#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

unfortunately most of my experience in db programming is in postgreSQL, and the foreign keys work a lot better there it seems. 不幸的是,我在数据库编程方面的大部分经验是在postgreSQL中进行的,并且看起来那里的外键工作得更好。

EDIT: alright so the first problem was that my eyes were closed and the { } should be ( ) but now i am getting a new error 编辑:好的,所以第一个问题是我闭上了眼睛,{}应该是(),但是现在我遇到了一个新错误

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

here is the full ddl.sql (... is other columns, this table is creating fine though) 这是完整的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;

Use round parenthesis pair () . 使用圆括号对() NOT the curly ones {} . 不是卷曲的{}

Also make sure you have created user table with an id column with exact same type first. 另外,请确保首先创建的user表的id列的类型完全相同

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM