I've imported government data from txt files into a database. I'm trying to set up a foreign key relationship like so:
alter table ar_disbursements_emp_off add constraint
fk foreign key (lm2_year, rpt_id) references lm_data(lm2_year, rpt_id)
#1452 - Cannot add or update a child row: a foreign key constraint fails (
lm2_data
.#sql-b84_843
, CONSTRAINTfk
FOREIGN KEY (lm2_year
,rpt_id
) REFERENCESlm_data
(lm2_year
,rpt_id
))
Apparently, some data in the foreign key columns does not exist in the reference column. I'm not sure why this is but I'm trying to figure out if this issue is fixable. What query can I run that will show me the non-existent values in the referenced table?
I'd argue that this is not an exact duplicate because I'm trying to match a multiple column foreign key to the referenced table. In other words, I want to make sure ('lm2_year' . 'rpt_id')
in foreign key table equals ('lm2_year' . 'rpt_id')
in the referenced table.