简体   繁体   中英

sqlite3.OperationalError: database is locked

I'm trying to insert all values of a list to my sqlite3 database. When I simulate this query by using the python interactive interpreter, I am able to insert the single value to DB properly. But my code fails while using an iteration:

...
connection=lite.connect(db_name)
cursor=connection.cursor()
for name in match:
         cursor.execute("""INSERT INTO video_dizi(name) VALUES (?)""",(name,))
connection.commit()
...

error:cursor.execute("""INSERT INTO video_dizi(name) VALUES (?)""",(name,))
sqlite3.OperationalError: database is locked

Any way to overcome this problem?

当您尝试提交失败的操作时,您在代码中的其他位置是否有另一个用于开始仍处于活动状态(未提交)的事务的连接?

Because your database is use by another process or connection. If you need real concurrency, use a real RDBMS.

As this error can happen because you have opened your site.db or database file in DBbrowser type application to view in interactive database interface. Just close that it will work fine.

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