title: How to resolve 'Integrity constraint violation', 'a foreign key constraint fails' in Symfony2
body: <p>$ php app/console doctrine:schema:update --force<br>
  Updating database schema...</p>
  
  <pre><code>[Doctrine\DBAL\DBALException]                                                
    An exception occurred while executing 'ALTER TABLE my_data_and_attribute
    ADD CONSTRAINT FK_44E5AE29CAA2B25 FOREIGN KEY (data_id) REFEREN  
    CES my_data (id)':                                                
  
    SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update   
    a child row: a foreign key constraint fails (`symfony`.`#sql-3e2_186`, CONSTR  
    AINT `FK_44E5AE29CAA2B25` FOREIGN KEY (`data_id`) REFERENCES `my_data` (`id`)) 
  </code></pre>
  
  <p>An error has occurred.<br>
  I had recently replace data from other database that had execute update command.<br>
  So, I think the cause of error is that I had done replace data.<br>
  (I don't know what it may cause from completely different something.)</p>
  
  <p>And I also try to change relationship from phpMyAdmin.<br>
  But it failed like this.</p>
  
  <pre><code>Error
  
  SQL query:
  
  ALTER TABLE `my_data_and_attribute` ADD FOREIGN KEY ( `data_id` ) REFERENCES `symfony`.`my_data` (
  `id`
  ) ON DELETE CASCADE ON UPDATE RESTRICT ;
  
  MySQL said: Documentation
  #1452 - Cannot add or update a child row: a foreign key constraint fails (`symfony`.`#sql-3e9_1ea`, CONSTRAINT `#sql-3e9_1ea_ibfk_2` FOREIGN KEY (`data_id`) REFERENCES `my_data` (`id`) ON DELETE CASCADE) 
  </code></pre>
  
  <p>I can't understand this error messages.<br>
  Where should I check for?</p>
  
  <hr>
  
  <p>symfony.my_data</p>
  
  <pre><code>#   Column  Type    Collation   Attributes  Null    Default     Extra         
  1   id      int(11)                         No      None        AUTO_INCREMENT
  // ...
  
  Indexes:
  Keyname Type    Unique  Packed  Column  Cardinality Collation   Null    Comment
  PRIMARY BTREE   Yes     No      id      517         A
  </code></pre>
  
  <p>symfony.my_data_and_attribute</p>
  
  <pre><code>#   Column          Type    Collation   Attributes  Null    Default Extra
  1   data_id         int(11)                         No      None    
  2   attribute_id    int(11)                         No      None    
  
  INDEXES
  Keyname         Type    Unique  Packed  Column      Cardinality Collation   Null    Comment
  PRIMARY         BTREE   Yes     No      data_id     483         A       
                                          attribute_id483         A   
  data_id         BTREE   No      No      data_id     483         A       
  attribute_id    BTREE   No      No      attribute_id37          A
  </code></pre>
  
  <p>Relation view</p>
  
  <pre><code>Column      Internal relation   Foreign key constraint (INNODB)
  data_id                                                         // &lt;- I can not set value this point.
  attribute_id                    `symfony`.`my_attribute`.`id`   ON DELETE CASCADE ON UPDATE RESTRICT  
  </code></pre>