title: Foreign key creation
body: <p>I am having some trouble adding a foreign key constraint to a table in my MySQL-database.</p>
  
  <p>I have the following <strong>user</strong> table:</p>
  
  <pre><code>CREATE TABLE `user` (
     `Id` varchar(128) NOT NULL,
     `Email` varchar(255) NOT NULL,
     `EmailConfirmed` tinyint(1) NOT NULL,
     `PasswordHash` longtext,
     `SecurityStamp` longtext,
     `PhoneNumber` longtext,
     `PhoneNumberConfirmed` tinyint(1) NOT NULL,
     `TwoFactorEnabled` tinyint(1) NOT NULL,
     `LockoutEndDateUtc` datetime DEFAULT NULL,
     `LockoutEnabled` tinyint(1) NOT NULL,
     `AccessFailedCount` int(11) NOT NULL,
     `UserName` varchar(255) NOT NULL,
     PRIMARY KEY (`Id`)
   ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  </code></pre>
  
  <p>And this is my usernotice table I'm trying to add a foreign key to:</p>
  
  <pre><code>CREATE TABLE `usernotice` (
     `id` int(11) NOT NULL AUTO_INCREMENT,
     `notifySitemap` bit(1) NOT NULL,
     `notifyRobots` bit(1) NOT NULL,
     `user_id` varchar(128) DEFAULT NULL,
     `health_site_id` int(11) DEFAULT NULL,
     PRIMARY KEY (`id`),
     KEY `user_constraint_idx` (`user_id`),
     KEY `healthSiteId_idx` (`health_site_id`),
     CONSTRAINT `healthSiteId` FOREIGN KEY (`health_site_id`) REFERENCES `health_site` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
   ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  </code></pre>
  
  <p>I'm trying to reference the user.id column in the usernotice.user_id column. To do this I'm using the following SQL:</p>
  
  <pre><code>ALTER TABLE usernotice
  ADD CONSTRAINT userId
    FOREIGN KEY (user_id)
    REFERENCES user (Id)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION;
  </code></pre>
  
  <p>When I execute this I get an error with a 1215 code. Can anyone tell me what I'm doing wrong? </p>
  
  <p><strong>EDIT:</strong> After inspecting the <code>show create table</code> querys I noticed a difference in the charset used. Recreating the <code>usernotice</code> table with another charset fixed this.</p>