简体   繁体   中英

Problem in insertion from python script in mysql database with innondb engine

I am facing a problem where I am trying to add data from a python script to mysql database with InnonDB engine, it works fine with myisam engine of the mysql database. But the problem with the myisam engine is that it doesn't support foreign keys so I'll have to add extra code each place where I want to insert/delete records in database.

Does anyone know why InnonDB doesn't work with python scripts and possible solutions for this problem??

InnoDB is transactional. You need to call connection.commit() after inserts/deletes/updates.

Edit: you can call connection.autocommit(True) to turn on autocommit.

Python DB API disables autocommit by default

Pasted from google (first page, 2nd result)

MySQL :: MySQL 5.0 Reference Manual :: 13.2.8 The InnoDB ... By default, MySQL starts the session for each new connection with autocommit ... dev.mysql.com/.../innodb-transaction-model.html

However

Apparently Python starts MySQL in NON-autocommit mode, see:
http://www.kitebird.com/articles/pydbapi.html

From the article:

The connection object commit() method commits any outstanding changes in the current transaction to make them permanent in the database. In DB-API, connections begin with autocommit mode disabled , so you must call commit() before disconnecting or changes may be lost.

Bummer, dunno how to override that and I don't want to lead you astray by guessing. I would suggest opening a new question titled:

How to enable autocommit mode in MySQL python DB-API?

Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM