SQLite外键不匹配错误

前端之家收集整理的这篇文章主要介绍了SQLite外键不匹配错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
为什么我在执行下面的脚本时遇到sqlite“外键不匹配”错误
DELETE 
FROM rlsconfig 
WHERE importer_config_id=2 and 
program_mode_config_id=1

这是主表定义:

CREATE TABLE [RLSConfig] (
        "rlsconfig_id"      integer PRIMARY KEY AUTOINCREMENT NOT NULL,"importer_config_id"        integer NOT NULL,"program_mode_config_id"        integer NOT NULL,"l2_channel_config_id"      integer NOT NULL,"rls_fixed_width"       integer NOT NULL,FOREIGN KEY ([importer_config_id])
            REFERENCES [ImporterConfig]([importer_config_id]),FOREIGN KEY ([program_mode_config_id])
            REFERENCES [ImporterConfig]([importer_config_id]),FOREIGN KEY ([importer_config_id])
            REFERENCES [ImporterConfig]([program_mode_config_id]),FOREIGN KEY ([program_mode_config_id])
            REFERENCES [ImporterConfig]([program_mode_config_id])
    )

和引用表:

CREATE TABLE [ImporterConfig] (
        "importer_config_id"        integer NOT NULL,"selected"      integer NOT NULL DEFAULT 0,"combined_config_id"        integer NOT NULL,"description"       varchar(50) NOT NULL COLLATE NOCASE,"date_created"      datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),PRIMARY KEY ([program_mode_config_id],[importer_config_id]),FOREIGN KEY ([program_mode_config_id])
            REFERENCES [ProgramModeConfig]([program_mode_config_id])
    )
在具有复合主键的表上使用外键时,必须使用复合外键以及所引用表的主键中的所有字段.

例:

CREATE TABLE IF NOT EXISTS parents
(
    key1 INTEGER NOT NULL,key2 INTEGER NOT NULL,not_key INTEGER DEFAULT 0,PRIMARY KEY ( key1,key2 )
);


CREATE TABLE IF NOT EXISTS childs
(
    child_key INTEGER NOT NULL,parentKey1 INTEGER NOT NULL,parentKey2 INTEGER NOT NULL,some_data INTEGER,PRIMARY KEY ( child_key ),FOREIGN KEY ( parentKey1,parentKey2 ) REFERENCES parents( key1,key2 )
);
原文链接:https://www.f2er.com/sqlite/197873.html

猜你在找的Sqlite相关文章