我试图在php中创建一个表,但是每次我运行它时,它总是说表中不存在键列'survey_type_id'
survey_type表
$sql = "CREATE TABLE survey_type (
survey_type_id INT NOT NULL AUTO_INCREMENT,
type VARCHAR(40),
PRIMARY KEY(survey_type_id))";
调查表
$sql = "CREATE TABLE survey(
id INT NOT NULL AUTO_INCREMENT,
username VARCHAR(64),
title VARCHAR(150),
instructions VARCHAR(250),
PRIMARY KEY(id),
FOREIGN KEY(username) REFERENCES users(username),
FOREIGN KEY(survey_type_id) REFERENCES survey_type(survey_type_id))";
最佳答案
看一下此语句,问题应该很明显:
CREATE TABLE survey
(
id INT NOT NULL AUTO_INCREMENT,
username VARCHAR(64),
title VARCHAR(150),
instructions VARCHAR(250),
PRIMARY KEY(id),
FOREIGN KEY(username) REFERENCES users(username),
FOREIGN KEY(survey_type_id) REFERENCES survey_type(survey_type_id)
)
该语句在
survey.survey_type_id
和survey_type.survey_type_id
两列之间创建外键。但是,
survey_type_id
表上没有名为survey
的列。创建
survey
表的语句应包含survey_type_id
列的定义: ...
instructions VARCHAR(250),
survey_type_id INT,
PRIMARY KEY(id),
...
关于php - 我该如何解决表中不存在键列“survey_type_id”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59155903/