title: MySQL Creating tables with Foreign Keys giving error [3780]
body: <p>I am using RMariaDB with the code</p>
  <pre><code>ALTER TABLE `general_pop_estimates` ADD FOREIGN KEY (`country_code`) REFERENCES `countries` (`country_code`);
  </code></pre>
  <p>and it gives the error</p>
  <blockquote>
  <p>Error: Referencing column 'country_code' and referenced column 'country_code' in foreign key constraint 'general_pop_estimates_ibfk_1' are incompatible. [3780]</p>
  </blockquote>
  <p>This is in spite them having same character type as shown below</p>
  <pre><code>CREATE TABLE IF NOT EXISTS `countries` (
    `country_code` varchar(255) PRIMARY KEY,
    `name` varchar(255)
  );
  </code></pre>
  <pre><code>CREATE TABLE IF NOT EXISTS `general_pop_estimates` (
    `gen_id` int PRIMARY KEY AUTO_INCREMENT,
    `estimates` int,
    `country_code` varchar(255)
  );
  </code></pre>
  <p>I tried to use as a remedy</p>
  <pre><code>ALTER TABLE tablename CHARACTER SET utf8 COLLATE utf8_general_ci;
  </code></pre>
  <p>but the issue persisted.</p>
  <p>I am not sure what is the issue. Any help is appreciated.</p>