【发布时间】:2020-12-02 10:56:40
【问题描述】:
我将 sqlite3 (import sqlite3) 与 python 一起使用,但我无法将 db 文件保存在磁盘上(在我的情况下,在 heroku 上,在 /app/ 内)。运行时没有错误:
c = sqlite3.connect(':memory:')
c.execute('CREATE TABLE users (userid int, isbot boolean);')
c.execute("INSERT INTO users VALUES (000000000, 'test');")
c.commit()
c2 = sqlite3.connect('/app/bot.db')
with c2:
for line in c.iterdump():
if line not in ('BEGIN;', 'COMMIT;'): # let python handle the transactions
c2.execute(line)
c2.commit()
【问题讨论】:
-
SQLite 与 Heroku 不兼容。这是有据可查的,in official documentation 和 in questions here。您必须迁移到真正的客户端-服务器数据库。
标签: python database sqlite heroku disk