sqlalchemy-migrate DatabaseNotControlledError异常

时间:2014-08-20 09:05:07

标签: python python-2.7 sqlalchemy sqlalchemy-migrate

我想在现有数据库中添加一个新列,最初由sqlalchemy创建。

我尝试使用sqlalchemy-migrate工具执行此操作并遇到以下错误:

C:\Users\sk11\Desktop\playground\migrateDB>%PYTHON_EXE% manage.py db_version
Traceback (most recent call last):
  File "manage.py", line 5, in <module>
    main(url='sqlite:///Results.db', debug='False', repository='sdb')
  File "C:\Python27\lib\site-packages\sqlalchemy_migrate-0.7.2-py2.7.egg\migrate\versioning\shell.py", line 207, in main
    ret = command_func(**kwargs)
  File "<string>", line 2, in db_version
  File "C:\Python27\lib\site-packages\sqlalchemy_migrate-0.7.2-py2.7.egg\migrate\versioning\util\__init__.py", line 159, in with_engine
    return f(*a, **kw)
  File "C:\Python27\lib\site-packages\sqlalchemy_migrate-0.7.2-py2.7.egg\migrate\versioning\api.py", line 148, in db_version
    schema = ControlledSchema(engine, repository)
  File "C:\Python27\lib\site-packages\sqlalchemy_migrate-0.7.2-py2.7.egg\migrate\versioning\schema.py", line 32, in __init__
    self.load()
  File "C:\Python27\lib\site-packages\sqlalchemy_migrate-0.7.2-py2.7.egg\migrate\versioning\schema.py", line 44, in load
    self.table = Table(tname, self.meta, autoload=True)
  File "build\bdist.win32\egg\sqlalchemy\schema.py", line 318, in __new__
  File "build\bdist.win32\egg\sqlalchemy\schema.py", line 381, in _init
  File "build\bdist.win32\egg\sqlalchemy\schema.py", line 408, in _autoload
  File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 2426, in run_callable
  File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 1969, in run_callable
  File "build\bdist.win32\egg\sqlalchemy\engine\default.py", line 260, in reflecttable
  File "build\bdist.win32\egg\sqlalchemy\engine\reflection.py", line 412, in reflecttable
migrate.exceptions.DatabaseNotControlledError: migrate_version

我按照与docs中说明的步骤完全相同的步骤。在检查db_version之前(我得到了上述错误)我尝试了version命令工作正常。

C:\Users\sk11\Desktop\playground\migrateDB>C:\Python27\Scripts\migrate.exe manage manage.py --repository=sdb --url=sqlite:///Results.db

C:\Users\sk11\Desktop\playground\migrateDB>%PYTHON_EXE% manage.py version
0

任何想要进一步观察或我做错了什么的想法?

1 个答案:

答案 0 :(得分:2)

我意识到数据库没有添加到存储库版本控制中。

由于我的存储库下有多个数据库,我添加了错误的数据库而不是我想要的数据库。

$ python my_repository/manage.py version_control sqlite:///project.db my_repository