我已经只有一个表'类别'与' id_category',' rgt'和' lft'列。
当我尝试创建表时:
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),
^
答案 0 :(得分:0)
我认为key
中的KEY id_category (id_category),
旨在成为唯一索引。以下是您可能需要的示例:
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
) ;