Python 内存数据库中sqlite的Alembic stamp命令问题
我在使用alembic的stamp命令和使用sqlite内存数据库进行测试时遇到了一些问题。与基于文件的sqlite dbs完美配合的测试失败,原因是Python 内存数据库中sqlite的Alembic stamp命令问题,python,sqlite,sqlalchemy,alembic,Python,Sqlite,Sqlalchemy,Alembic,我在使用alembic的stamp命令和使用sqlite内存数据库进行测试时遇到了一些问题。与基于文件的sqlite dbs完美配合的测试失败,原因是OperationalError:(OperationalError)没有这样的表 我在初始化过程中盖章,以显示数据库是最新的: def init_db(engine, version): tables.Base.metadata.create_all(engine) with engine.begin() as connectio
OperationalError:(OperationalError)没有这样的表
我在初始化过程中盖章,以显示数据库是最新的:
def init_db(engine, version):
tables.Base.metadata.create_all(engine)
with engine.begin() as connection:
stamp_alembic(connection)
def stamp_alembic(connection):
from alembic import command
from alembic.config import Config
alembic_cfg = Config('alembic.ini')
alembic_cfg.attributes['connection'] = connection
command.stamp(alembic_cfg, 'head')
我正在将当前连接传递到env.py
:
我的测试班:
SETTINGS = {'sqlalchemy.url': 'sqlite:///:memory:'}
class TestOperatorUserModel(unittest.TestCase):
def setUp(self):
engine = engine_from_config(SETTINGS, 'sqlalchemy.')
tables.DBSession.configure(bind=engine)
init_db(engine, SETTINGS['version.db'])
transaction.begin()
def tearDown(self):
engine = engine_from_config(SETTINGS, 'sqlalchemy.')
transaction.abort()
tables.Base.metadata.drop_all(engine)
tables.DBSession.remove()
如果我从初始化中删除stamp调用,测试也可以正常运行。作为一种解决方法,我只在engine.url.database
不是':memory:'
的情况下在db上加盖戳记,但我希望知道问题的真正根源是什么
环境是Python 2.7.11、SQLAlchemy 0.9.10、alembic 0.8.6和sqlite 2.8.17
SETTINGS = {'sqlalchemy.url': 'sqlite:///:memory:'}
class TestOperatorUserModel(unittest.TestCase):
def setUp(self):
engine = engine_from_config(SETTINGS, 'sqlalchemy.')
tables.DBSession.configure(bind=engine)
init_db(engine, SETTINGS['version.db'])
transaction.begin()
def tearDown(self):
engine = engine_from_config(SETTINGS, 'sqlalchemy.')
transaction.abort()
tables.Base.metadata.drop_all(engine)
tables.DBSession.remove()