Alembic Migrations for Flask

梦想与她 提交于 2019-12-11 19:24:54

问题


I have been trying to get the Alembic migration system configured for my Flask app for the past 7 hours with no success. Any ideas as to what I am doing wrong?

I have tried all the solutions I found here, but they did not seem to work for me.

I get the following error after running the commands:
$ heroku run alembic revision -m "please work" --autogenerate
Running `alembic revision -m please work --autogenerate` attached to terminal... up, run.6050
Traceback (most recent call last):
  File "/app/.heroku/python/bin/alembic", line 9, in <module>
    load_entry_point('alembic==0.5.0', 'console_scripts', 'alembic')()
  File "/app/.heroku/python/lib/python2.7/site-packages/pkg_resources.py", line 337, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/app/.heroku/python/lib/python2.7/site-packages/pkg_resources.py", line 2281, in load_entry_point
    return ep.load()
  File "/app/.heroku/python/lib/python2.7/site-packages/pkg_resources.py", line 1991, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])

ImportError: No module named config

Also, note, I am trying to get it to work on Heroku

A portion of my env.py file:

from alembic import context
config = context.config

I'd appreciate any help I can get, or maybe suggestions to a simpler solution for easy migrations with Flask.

Thanks.


This is how I add a migration on Heroku. Is this correct?

heroku run alembic revision -m "add Content table" --autogenerate

回答1:


You should be generating revisions only on your development machine, on production (Heroku in this case), you should only be applying them.

You can set up Alembic to migrate your production machine from your development machine. A command line argument can tell it to point at a different database URL. See the docs for an example.



来源:https://stackoverflow.com/questions/17501082/alembic-migrations-for-flask

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!