title: Unique Constraint on Foreign Key Columns
body: <p>I'm trying to add a <code>unique constraint</code> to two foreign keys:</p>
  
  <pre><code>CREATE TABLE tagsInBlog(
      id_tag int(10) not null auto_increment,
      id_word int(10) not null,
      id_page int(11),
      PRIMARY KEY(id_tag),
      FOREIGN KEY (id_page) REFERENCES archive(id),
      FOREIGN KEY (id_word) REFERENCES tagwords(id_word)
  )ENGINE=INNODB DEFAULT CHARSET=utf8;
  
  ALTER TABLE tagsinblog
    ADD UNIQUE tagBlogConstraint (id_word, id_page);
  </code></pre>
  
  <p>When creating I don't get any errors, but when I'm trying to insert I get:</p>
  
  <blockquote>
    <p>MYSQL ERROR 367421 (could not save new tag data into Mysql): Error
    1452 (23000):  Cannot add or update a child row: a foreign key
    constraint fails (<code>sqse_001</code>.<code>tagsinblog</code>, CONSTRAINT
    <code>tagsinblog_ibfk_2</code>  FOREIGN KEY (<code>id_word</code>) REFERENCES <code>tagwords</code>
    (<code>id_word</code>))</p>
  </blockquote>
  
  <p>When I'm trying to insert in the same table without the unique constraint I don't have any problems.    </p>