title: How can I add primary/foreign key to table made by to_sql?
body: <p>I would like to "Add primary or foreign key" to table made using to_sql of  Python dataframe. Here is some of my Python code. </p>
  
  <p>This causes "sqlite3.OperationalError: no such table:  is_year_002620"
  But I checked is_year_002620 table created. </p>
  
  <p>I have no idea why this isn't working. How can I "add primary key" to table made by to_sql?</p>
  
  <pre><code>for i in range(startrow, endrow):    
      if df is not None:
          table_name = 'is_year_' + code #code is variable of 6 digit number  and its number is about 1,800  
          df.to_sql(table_name, conn, if_exists='append', index=False)
          conn.cursor().execute("""ALTER TABLE" %s "ADD PRIMARY KEY (code)""" %(table_name))
  </code></pre>