数据库中带有SqlAlchemy CreateTable结果的SqlLite被锁定

时间:2018-09-04 09:19:36

标签: python sqlite sqlalchemy

在试图弄清为什么测试无法创建sqlite模式时,我尝试了一个非常简单的示例,该示例由https://pysheeet.readthedocs.io/en/latest/notes/python-sqlalchemy.html

发布
from sqlalchemy import create_engine
from sqlalchemy import MetaData
from sqlalchemy import Table
from sqlalchemy import Column
from sqlalchemy import Integer, String

db_uri = 'sqlite:///db.sqlite'
engine = create_engine(db_uri)

# Create a metadata instance
metadata = MetaData(engine)
# Declare a table
table = Table('Example',metadata,
              Column('id',Integer, primary_key=True),
              Column('name',String))
# Create all tables
metadata.create_all()
for _t in metadata.tables:
   print("Table: ", _t)

但是我仍然收到此数据库锁定消息:

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) database is locked [SQL: '\nCREATE TABLE "Example" (\n\tid INTEGER NOT NULL, \n\tname VARCHAR, \n\tPRIMARY KEY (id)\n)\n\n'] (Background on this error at: http://sqlalche.me/e/e3q8)

关于如何在非“内存中” sqlite db中使用create all的任何想法?

0 个答案:

没有答案