Hi I create table MySQL but I can't create table FOREIGN KEY use VARCHAR Data Type
The First table didn't have ERROR
CREATE TABLE device_list (
id INT NOT NULL AUTO_INCREMENT ,
stationcode VARCHAR(80) ,
devtypeid varchar(20),
deviceid varchar(20),
time_save time,
date_save date,
PRIMARY KEY (id),
FOREIGN KEY (stationcode) REFERENCES plant_name(plant_name)
);
The Second Table did have ERROR 1822
CREATE TABLE Device_Data_String(
id INT NOT NULL AUTO_INCREMENT ,
devIds VARCHAR(20) ,
MPPT_1 varchar(100),
MPPT_2 varchar(100),
MPPT_3 varchar(100),
MPPT_4 varchar(100),
MPPT_5 varchar(100),
run_state varchar(100),
Date_save timestamp,
PRIMARY KEY (id),
FOREIGN KEY (devIds) REFERENCES device_list(deviceid)
);
Error Respond
Error Code: 1822. Failed to add the foreign key constraint. Missing index for constraint 'device_data_string_ibfk_1' in the referenced table 'device_list'
thank you very much.