我正在使用外键,不幸的是,在这种情况下,我无法解决不匹配问题...我错过了什么? tebles由以下人员创建:
CREATE TABLE IF NOT EXISTS `devices` (
`guid` BLOB NOT NULL,
`device_name` TEXT NOT NULL,
`class` INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS `device_states` (
`guid_d` BLOB NOT NULL,
`id_d` TEXT DEFAULT NULL,
`tp` INTEGER NOT NULL,
`state` INTEGER NOT NULL,
`note` TEXT DEFAULT NULL,
`status` INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY(`guid_d`,`tp`),
FOREIGN KEY(`guid_d`) REFERENCES devices ( `guid` ) ON DELETE RESTRICT
);
CREATE INDEX IF NOT EXISTS idx_ds_tp ON device_states(`tp`);
INSERT OR IGNORE INTO `devices` VALUES (x'438D6E77DC3946A4819617ADBA18ADB2','guid_door', 1);
选择波纹管按预期工作:
SELECT * FROM `devices` WHERE guid = x'438D6E77DC3946A4819617ADBA18ADB2';
返回1行:SELECT * FROM
devices
WHERE guid = x' 438D6E77DC3946A4819617ADBA18ADB2&#39 ;; (花了1毫秒)
但是,当我尝试将数据插入 devices 表时,我收到错误...
INSERT INTO device_states (guid_d, id_d, tp, state, note, status)
VALUES (x'438D6E77DC3946A4819617ADBA18ADB2', "D", 132456, 1, "door open", 2);
外键不匹配 - " device_states"引用"设备":INSERT INTO device_states(guid_d,id_d,tp,state,note,status)VALUES (x' 438D6E77DC3946A4819617ADBA18ADB2'," D",132456,1,"开门",2);
有人看到这个问题吗???非常感谢!
答案 0 :(得分:1)