title: Python pandas to_sql 'append'
body: <p>I am trying to send monthly data to a MySQL database using Python's pandas to_sql command. My program runs one month of data at a time and I want to append the new data onto the existing database. However, Python gives me an error:</p>
  
  <pre><code>_mysql_exceptions.OperationalError: (1050, "Table 'cps_basic_tabulation' already exists")
  </code></pre>
  
  <p>Here is my code for connecting and exporting:</p>
  
  <pre><code>conn = MySQLdb.connect(host     = config.get('db', 'host'),
                         user     = config.get('db', 'user'),
                         passwd   = config.get('db', 'password'),
                         db       = 'cps_raw') 
  
  combined.to_sql(name            = "cps_raw.cps_basic_tabulation",
                 con              = conn,
                 flavor           = 'mysql', 
                 if_exists        = 'append')
  </code></pre>
  
  <p>I have also tried using:</p>
  
  <pre><code>from sqlalchemy import create_engine
  </code></pre>
  
  <p>Replacing conn = MySQLdb.connect... with:</p>
  
  <pre><code>engine = mysql+mysqldb://&lt;user&gt;:&lt;password&gt;@&lt;host&gt;[:&lt;port&gt;]/&lt;dbname&gt;
  
  conn   = engine.connect().connection
  </code></pre>
  
  <p>Any ideas on why I cannot append to a database?</p>
  
  <p>Thanks!</p>