错误 1048。Mysql 查找 table 中的列不能为空 - 缺少什么?
error 1048. column cannot be null in Mysql lookup table-something missing?
我想将数据添加到查找中 table
locations_borrowers
(id_location_borrower(PK),id_borrower(FK),id_location(FK))
来自 3 个不同的 table:
borrowers
(id_borrower (PK), 名字, 姓氏)
locations
(id_location(PK),街道,城镇)
all_proto
(borrower_forename,borrower_surname,街道,城镇,职业,电话)
我写了以下内容:
INSERT INTO schema.locations_borrowers (id_borrower, id_location)
SELECT borrowers.id_borrower, locations.id_location FROM borrowers JOIN schema.all_proto
ON borrowers.forename = all_proto.borrower_forename AND borrowers.surname = all_proto.borrower_surname
LEFT JOIN locations ON locations.street = all_proto.street AND locations.town = all_proto.town;
我收到 1048 错误,怎么了?
MySQL :: 错误:1048 插入的列不能为空
由于您正在使用 LEFT JOIN
,因此列 locations.id_location
可能为空。
这应该始终是 INNER JOIN
,因为您希望这两个值都是 NOT NULL
。 (如果不是,table 没有任何意义,不是吗?)
我想将数据添加到查找中 table
locations_borrowers
(id_location_borrower(PK),id_borrower(FK),id_location(FK))
来自 3 个不同的 table:
borrowers
(id_borrower (PK), 名字, 姓氏)locations
(id_location(PK),街道,城镇)all_proto
(borrower_forename,borrower_surname,街道,城镇,职业,电话)
我写了以下内容:
INSERT INTO schema.locations_borrowers (id_borrower, id_location)
SELECT borrowers.id_borrower, locations.id_location FROM borrowers JOIN schema.all_proto
ON borrowers.forename = all_proto.borrower_forename AND borrowers.surname = all_proto.borrower_surname
LEFT JOIN locations ON locations.street = all_proto.street AND locations.town = all_proto.town;
我收到 1048 错误,怎么了?
MySQL :: 错误:1048 插入的列不能为空
由于您正在使用 LEFT JOIN
,因此列 locations.id_location
可能为空。
这应该始终是 INNER JOIN
,因为您希望这两个值都是 NOT NULL
。 (如果不是,table 没有任何意义,不是吗?)