问题
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