title: duplicate entry for key primary errors while replicating a table
body: <p>I have some CRM data that exists in a MS SQL server, that I must move to mysql daily.  I've got some python-pandas, read_sql() and to_sql() scripts that move the tables.  I'm running into duplicate primary keys errors after doing some upsert logic. I have the GUID from CRM as the primary key for the table - in MySQL it is a varchar(64) datatype.  Unsure what's triggering the duplicate warning.</p>
  
  <p>mysql_table:</p>
  
  <pre><code>GUID-PK          Name      favorite_number  modifiedon
  00000B9D...      Ben            10          '2017-01-01'
  000A82A5...      Harry          9           '2017-05-15'
  000A9896...      Fred           5           '2017-12-19'
  </code></pre>
  
  <p>(the GUIDs are longer, i'm shortening for the example)
  I pull all the new records from MS SQL into a temporary table in MySQL based on modified dates that are greater than my current table.  Some of these could be new records some could be records that already exist in my current table but have been updated. </p>
  
  <p>mysql_temp_table:</p>
  
  <pre><code>GUID-PK          Name      favorite_number  modifiedon
  00000B9D...      Ben            15          '2018-01-01'
  000A82BB...      John           3           '2018-03-15'
  000A4455...      Ray            13          '2018-04-01'
  </code></pre>
  
  <p>I want to replace any modified records, straight up, so I delete all the common records from the mysql_table. In this example, I want to remove Ben from the mysql_table, so that it can be replaced by Ben from the mysql_temp_table:</p>
  
  <pre><code>DELETE FROM mysql_table WHERE GUID-PK IN (SELECT GUID-PK FROM mysql_temp_table) 
  </code></pre>
  
  <p>Then I want to just move the whole temp table into the replicated table with:</p>
  
  <pre><code>INSERT INTO mysql_table (SELECT * FROM temp_table)
  </code></pre>
  
  <p>But that gives me an error:</p>
  
  <pre><code>"Duplicate entry '0' for key 'PRIMARY'") [SQL: 'INSERT INTO mysql_table SELECT * FROM mysql_temp_table'
  </code></pre>
  
  <p>I can see that many of the GUID's start with '000', it seems like this is being interpreted as '0'.  Shouldn't this be caught in the Delete-IN statement from above.  i'm stuck on where to go next. Thanks in advance.  </p>