SQL 尝试创建新 table 时出错
SQL error when try to create new table
我已经只有一个 table 'category' 和 'id_category'、'rgt' 和 'lft' 列。
当我尝试创建 Table:
CREATE TABLE category_translation(
id_category_translation int NOT NULL,
id_category int NOT NULL,
language_code varchar(5) NOT NULL,
title varchar(100) NOT NULL,
description varchar(255) NOT NULL,
PRIMARY KEY (id_category_translation),
KEY id_category (id_category),
CONSTRAINT category_translation_ibfk_1
FOREIGN KEY (id_category)
REFERENCES category (id_category)
ON DELETE CASCADE
)
出现此错误:
ERROR: type "id_category" does not exist
LINE 8: KEY id_category (id_category),
^
我假设 KEY id_category (id_category),
中的 key
是一个唯一索引。以下是您可能需要的示例:
create table category
(
id_category int primary key
) ;
create table category_translation
(
id_category_translation int primary key
, id_category int unique constraint category_translation_ibfk_1 references category on delete cascade
, language_code varchar(5) not null
, title varchar(100) not null
, description varchar(255) not null
) ;
我已经只有一个 table 'category' 和 'id_category'、'rgt' 和 'lft' 列。
当我尝试创建 Table:
CREATE TABLE category_translation(
id_category_translation int NOT NULL,
id_category int NOT NULL,
language_code varchar(5) NOT NULL,
title varchar(100) NOT NULL,
description varchar(255) NOT NULL,
PRIMARY KEY (id_category_translation),
KEY id_category (id_category),
CONSTRAINT category_translation_ibfk_1
FOREIGN KEY (id_category)
REFERENCES category (id_category)
ON DELETE CASCADE
)
出现此错误:
ERROR: type "id_category" does not exist
LINE 8: KEY id_category (id_category),
^
我假设 KEY id_category (id_category),
中的 key
是一个唯一索引。以下是您可能需要的示例:
create table category
(
id_category int primary key
) ;
create table category_translation
(
id_category_translation int primary key
, id_category int unique constraint category_translation_ibfk_1 references category on delete cascade
, language_code varchar(5) not null
, title varchar(100) not null
, description varchar(255) not null
) ;