SQLite3外键不匹配

时间:2019-06-22 05:02:23

标签: python sqlite

我用两个主键idid创建了一个名为host_id的表,并在其中插入了数据。然后,我创建了一个带有外键的表listing_info,该表引用了表id中的id列。我运行查询并遇到外键不匹配错误。

id表:

c1 = '''
CREATE TABLE IF NOT EXISTS id (
    id INTEGER,
    host_id INTEGER,
    PRIMARY KEY (id, host_id)
);
'''

c2 = '''
INSERT OR IGNORE INTO id
SELECT 
    id,
    host_id
FROM listings;
'''

listing_info表:

c1 = '''
CREATE TABLE IF NOT EXISTS listing_info (
    id INTEGER,
    neighborhood TEXT,
    latitude REAL,
    longitude REAL,
    room_type TEXT,
    price REAL,
    security_deposit REAL,
    cleaning_fee REAL,
    FOREIGN KEY (id) REFERENCES id(id)
);
'''

c2 = '''
INSERT OR IGNORE INTO listing_info
SELECT 
    id,
    neighbourhood,
    latitude,
    longitude,
    room_type,
    price,
    security_deposit,
    cleaning_fee
FROM listings;
'''

为什么我遇到外键不匹配?

0 个答案:

没有答案