Humphrey
Humphrey

Reputation: 2817

relational database queries are not working mysql

I am trying to create a relational database in MySql but i am getting an error and I really cant figure out what’s wrong with my query.

Below is the error is get :

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

Here is my query :

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;

Upvotes: 2

Views: 89

Answers (1)

lc.
lc.

Reputation: 116528

You do not have a user_id column in tish_clientinfor as referenced by FOREIGN KEY(user_id).... Did you perhaps mean to add one?

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;

The same is true for table tish_images.

Upvotes: 2

Related Questions