关系数据库查询不起作用mysql

时间:2013-01-26 12:59:32

标签: mysql

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

以下是错误:

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;

1 个答案:

答案 0 :(得分:2)

user_id引用的tish_clientinfor列中没有FOREIGN 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也是如此。