我試圖設置DEFAULT
值和NOT NULL
對於type_id
列,它是instance
表的外鍵,但它抱怨MySQL語法。添加外鍵約束時出現語法錯誤
CREATE TABLE `type` (
`id` int(10) unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
`city` varchar(256)
);
ALTER TABLE instance ADD COLUMN type_id int(10) unsigned NOT NULL;
ALTER TABLE instance ADD CONSTRAINT instance_xbf1 DEFAULT 1
FOREIGN KEY (type_id)
REFERENCES type(id) int(10) unsigned NOT NULL;
據抱怨最後一條語句的語法:
Error: \"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DEFAULT 1\nFOREIGN KEY (type_id)\nREFERENCES type(id) int(10) unsi' at line 1\")", "stdout": "", "stdout_lines": [], "warnings": []}
什麼是實際的錯誤信息? – ceejayoz
'這是抱怨MySQL語法'那些_complaints_包含非常具體的消息,告訴你到底是什麼錯誤。 –