title: How can I solve "Collation is not valid for CHARACTER SET 'latin1'"?
body: <p>I know this question is asked a lot but since I've tried every answer I wanted to ask again with more detailed information.</p>
  
  <p>I'm migrating data from a different database (different structured MySQL 5.6.34) to a MySQL 5.7.16</p>
  
  <p>I'm getting the following error for different tries;</p>
  
  <p>COLLATION 'utf8_unicode_ci/utf8_general_ci' is not valid for CHARACTER SET 'latin1'</p>
  
  <p>My parameter set is as</p>
  
  <pre><code> character_set_client =&gt;      utf8                                      
   character_set_connection =&gt;  utf8                                      
   character_set_database =&gt;    utf8                                      
   character_set_filesystem =&gt;  binary                                    
   character_set_results =&gt;     utf8                                      
   character_set_server =&gt;      utf8                                      
   character_set_system =&gt;      utf8                                     
   collation_connection =&gt;  utf8_general_ci   
   collation_database =&gt;    utf8_general_ci   
   collation_server =&gt;      utf8_unicode_ci
  </code></pre>
  
  <p>Also the two tables are set to utf8 and utf_general_ci respectively.</p>
  
  <p>Here is the insert query;</p>
  
  <pre><code>INSERT INTO t1 (detail)SELECT null_if_empty(detail) COLLATE utf_general_ci FROM t2;
  </code></pre>
  
  <p>Here is the function used "null_if_empty"</p>
  
  <pre><code>CREATE DEFINER=`root`@`localhost` FUNCTION `null_if_empty`(value TEXT) RETURNS text CHARSET utf8
  
  BEGIN DECLARE response_value TEXT DEFAULT NULL; IF (LENGTH(value) &gt; 0) THEN
  SET response_value = value; ELSE
  SET response_value = NULL; END IF; RETURN response_value; END;
  </code></pre>
  
  <p>PS:Both databases are kept on AWS RDS.</p>