2

我正在尝试在 MySql 中创建一个关系数据库,但我遇到了一个错误,我真的无法弄清楚我的查询出了什么问题。

下面是错误是 get :

Error Code : 1072
Key column 'user_id' doesn't exist in table
(0 ms taken)

这是我的查询:

CREATE TABLE tish_user(
user_id int(11) NOT NULL Auto_increment,
username varchar(30) NOT NULL,
Password varchar(41) NOT NULL,
Previllage VARCHAR(20) NOT NULL,
date_created datetime,
primary key (user_id )
)ENGINE=InnoDB;

CREATE TABLE tish_images(
image_id int(11) not null auto_increment,
image_name varchar(100) not null,
image_profile numeric(1) default 0,
FOREIGN KEY(user_id)REFERENCES tish_user(user_id)on update cascade,
primary key (image_id)
)ENGINE=InnoDB;


CREATE TABLE tish_clientinfor(
client_id int(11) not null auto_increment,
title  varchar(11) not null,
firstname varchar(30) not null,
lastname  varchar(30) not null,
client_code  varchar(30) not null,
date_registered  timestamp Default CURRENT_TIMESTAMP,
FOREIGN KEY(user_id)REFERENCES tish_user(user_id)on update cascade,
primary key (client_id)
)ENGINE=InnoDB;
4

1 回答 1

2

您在 中没有引用的user_id列。你是不是想加一个?tish_clientinforFOREIGN KEY(user_id)...

CREATE TABLE tish_clientinfor(
client_id int(11) not null auto_increment,
title  varchar(11) not null,
firstname varchar(30) not null,
lastname  varchar(30) not null,
client_code  varchar(30) not null,
date_registered  timestamp Default CURRENT_TIMESTAMP,
user_id int(11) not null, --this was the missing column
FOREIGN KEY(user_id)REFERENCES tish_user(user_id)on update cascade,
primary key (client_id)
)ENGINE=InnoDB;

表也​​是如此tish_images

于 2013-01-26T13:01:51.670 回答