title: Adding foreign key constraint failure
body: <p>I am trying to add a constraint in my tables and I keep getting the following </p>
  
  <blockquote>
    <p>11:11:55  ALTER TABLE adggtnz.lng01_rpt_animrec ADD CONSTRAINT 'fk20_lng01_rpt_animrec_reg04_rpt_animreg'  FOREIGN KEY ('animalid')
    REFERENCES 'reg04_rpt_animreg' ('animalid')   </p>
    
    <p>Error Code: 1452. Cannot
    add or update a child row: a foreign key constraint fails
    ('adggtnz'.'#sql-74e_2219446', CONSTRAINT
    'fk20_lng01_rpt_animrec_reg04_rpt_animreg' FOREIGN KEY ('animalid')
    REFERENCES 'reg04_rpt_animreg' ('animalid'))  0.077 sec</p>
  </blockquote>
  
  <p>I have used the following query to add my constraint</p>
  
  <pre><code>ALTER TABLE adggtnz.lng01_rpt_animrec 
  ADD CONSTRAINT 'fk20_lng01_rpt_animrec_reg04_rpt_animreg' 
  FOREIGN KEY ('animalid') REFERENCES 'reg04_rpt_animreg' ('animalid');
  </code></pre>
  
  <p>How can I ran the following query successfully and avoid an error as a result
  example of lng01_rpt_animrec:<br>
  column name</p>
  
  <pre><code>animalid,milkdate
  
  '0065ae2f-62b2-45dd-b0c4-e6479e57e4c8', NULL
  '0065ae2f-62b2-45dd-b0c4-e6479e57e4c8', '2018-05-29'
  '0065ae2f-62b2-45dd-b0c4-e6479e57e4c8', NULL
  '0065ae2f-62b2-45dd-b0c4-e6479e57e4c8', '2017-09-22'
  '02db813b-c2a4-4ce1-802e-51f48e1d93ba', '2018-05-07'
  '02db813b-c2a4-4ce1-802e-51f48e1d93ba', '2018-06-29'
  '04f2d070-6336-4426-8e13-733872ee4bb3', '2018-01-02'
  '0555e8ce-ba91-4a00-8a1d-133ff849ef87', '2017-10-02'
  '05ab7837-005d-4494-8c32-f290cc83c1af', '2018-06-16'
  '05ab7837-005d-4494-8c32-f290cc83c1af', NULL
  </code></pre>
  
  <p>example of reg04_animreg:<br>
  columns:</p>
  
  <pre><code>hh_id,regdate,animalid
  
  '0', '2017-02-13', 'TZN000362738061'
  '0', '2017-02-13', 'TZN000362738062'
  '0', '2017-02-13', 'TZN000362738074'
  '00', '2018-01-20', 'TZN000404007294'
  '00000', '2017-06-14', 'TZN000404001178'
  '00000', '2017-06-14', 'TZN000404001179'
  '000000', '2017-07-21', 'TZN000403255840'
  '0000000000_DUP1', '2017-05-31', 'TZN000365694884'
  '0000000000_DUP2', '2017-06-06', 'TZN123456782234'
  '0099887764', '2017-03-19', '03b704e2-bcdd-46e0-85e8-f38f21f16507'
  </code></pre>