我用两个主键id
和id
创建了一个名为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;
'''
为什么我遇到外键不匹配?