我尝试在 MySQL Workbench 上创建一个表,但它显示错误:
"()" (closing parenthesis) is not valid input at this position when creating table
最后一个右括号:
create table generics (
idGen int unsigned not null auto_increment,
nameGen nvarchar (255) not null,
type_id int not null,
id2 int not null,
pk int not null,
active bit not null,
created_at datetime null,
updated_at datetime null,
created_by nvarchar(255) null,
updated_by nvarchar(255) null,
constraint primary key(idGen),
constraint foreign key(type_id)
)
我读过,有时在使用 BOM 保存为 UTF8 时遇到问题时会发生这种情况,但此查询尚未保存,而且我以前从未遇到过此问题,另外这是我第一次使用 nvarchar,所以我不知道它是否与此有关。
最佳答案
对于外键约束,您缺少 REFERENCES 部分。 该键应该指向另一个表中的主键。
A FOREIGN KEY in MySQL creates a link between two tables by one specific column of both tables. The specified column in one table must be a PRIMARY KEY and referred by the column of another table known as FOREIGN KEY.
请检查以下内容以供引用
create table generics1 (
type_id int not null,
constraint primary key(type_id)
);
create table generics (
idGen int unsigned not null auto_increment,
nameGen nvarchar (255) not null,
type_id int not null,
id2 int not null,
pk int not null,
active bit not null,
created_at datetime null,
updated_at datetime null,
created_by nvarchar(255) null,
updated_by nvarchar(255) null,
constraint primary key(idGen),
constraint foreign key(type_id) REFERENCES generics1(type_id)
);
关于mysql - 创建表时,右括号在此位置无效输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58677565/