我是mysql-python的新手并且引用了this。 以下是我的查询 -
TABLES['doctor_details'] = (
"CREATE TABLE `doctor_details` ("
" `dr_id` bigint NOT NULL AUTO_INCREMENT,"
" `doctor_link` varchar(40),"
" `doctor_name` varchar(40) NOT NULL,"
" `doctor_exp_years` float,"
" `doctor_qualification` varchar(40),"
" `doctor_phone_no` varchar(15),"
" `doctor_city` varchar(40),"
" `doctor_state` varchar(40),"
" `doctor_country` varchar(40),"
" `doctor_speciality` varchar(40),"
" `doctor_website_link` varchar(40),"
" `status` int NOT NULL,"
" PRIMARY KEY (`dr_id`)"
") ENGINE=InnoDB")
TABLES['hospital_details'] = (
"CREATE TABLE `hospital_details` ("
" `hospital_id` bigint NOT NULL AUTO_INCREMENT,"
" `dr_id` bigint NOT NULL,"
" `hospital_link` varchar(40),"
" `hospital_name` varchar(40),"
" `hospital_address` varchar(40),"
" `hospital_city` varchar(40),"
" `hospital_state` varchar(40),"
" `hospital_country` varchar(40),"
" `hospital_phone_no` varchar(15),"
" `hospital_speciality` varchar(40),"
" `doctor_link` varchar(40),"
" `hospital_website_link` varchar(40),"
" PRIMARY KEY (`hospital_id`)"
" CONSTRAINT `dr_idfk` FOREIGN KEY (`dr_id`)"
" REFERENCES `doctor_details` (`dr_id`) ON DELETE NO ACTION"
") ENGINE=InnoDB")
self.cursor.execute( TABLES['doctor_details'])
self.cursor.execute( TABLES['hospital_details'])
它给了我以下错误 -
ProgrammingError:1064(42000):您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在'CONSTRAINT dr_idfk
FOREIGN KEY(dr_id
)附近使用正确的语法参考doctor_details
(第1行的`dr_i'
道歉,如果我犯了一些愚蠢的错误,但欢迎以任何形式提供指导/帮助。
提前多多感谢。
答案 0 :(得分:0)
此行后缺少逗号
PRIMARY KEY (`hospital_id`)"
所以它应该是
PRIMARY KEY (`hospital_id`),"
然后再说一遍,我不做Python,所以这对我来说都是希腊语。