问题描述
我有两个表clinics
和consultations
。
每个咨询记录都属于一个诊所,因此我想将clinic_name
设置为引用clinic_name
表中clinics
的外键。但这会引发错误:
code: 'ER_FK_NO_INDEX_PARENT',errno: 1822,sqlMessage: "Failed to add the foreign key constraint. Missing index for constraint 'consultations_ibfk_1' in the referenced table 'clinics'",
诊所表:
const sql_createclinics =
"CREATE TABLE IF NOT EXISTS clinics(" +
"id INT AUTO_INCREMENT," +
"email VARCHAR(255) NOT NULL," +
"password VARCHAR(255) NOT NULL," +
"clinic_name VARCHAR(255) NOT NULL," +
"phone_num VARCHAR(15) NOT NULL," +
"address VARCHAR(255) NOT NULL," +
"PRIMARY KEY (id))";
**咨询表:**
const sql_createconsult =
"CREATE TABLE IF NOT EXISTS consultations(" +
"id INT AUTO_INCREMENT," +
"clinic_name VARCHAR(255)," +
"doctor_name VARCHAR(255)," +
"patient_name VARCHAR(255)," +
"diagnosis VARCHAR(255)," +
"medication VARCHAR(255)," +
"consultation_fee FLOAT," +
"datetime DATETIME DEFAULT CURRENT_TIMESTAMP," +
"PRIMARY KEY (id)," +
"FOREIGN KEY (clinic_name) REFERENCES clinics(clinic_name))";
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)