'sql_require_primary_key' -sending my dataframe to mysql server primary key


My python script extracts data from a CRM saves it into a data frame and then sends it to the DB.

when I run:


from sqlalchemy import create_engine
f= open("db credentials,txt", "r")  # parse credentials in txt to hide sensitive data
sql_conn = f.read()
conn = create_engine(sql_conn)
df.to_sql(name='test_trx_1day', con=conn, if_exists='replace', index=False)


I get the following error:


sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (3750, "Unable to create or change a table without
a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset t
his variable to avoid this message. Note that tables without a primary key can cause performance problems in row-ba
sed replication, so please consult your DBA before changing this setting.")


I'm running:
python: 3.7.3
pyCharm IDE - using top ide for web development
using pymysql as MySQL connector 

When I run my code on my machine and the destination is my local MYSQL DB it works!

Note: I am not that familiar with Linux env so I am learning as I go along.



1 Reply 1
Community Manager

@taran42 , @TLeong either of you smart people able to help out here?



Check out our Community Developer Blog
where we feature our Community driven developer podcast and how to content