我运行了命令heroku run init
并收到此错误。我该如何解决?
manager.run()
File "/app/.heroku/python/lib/python2.7/site-packages/flask_script/__init__.py", line 412, in run
result = self.handle(sys.argv[0], sys.argv[1:])
File "/app/.heroku/python/lib/python2.7/site-packages/flask_script/__init__.py", line 383, in handle
res = handle(*args, **config)
File "/app/.heroku/python/lib/python2.7/site-packages/flask_script/commands.py", line 216, in __call__
return self.run(*args, **kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/flask_migrate/__init__.py", line 61, in init
command.init(config, directory, 'flask')
File "/app/.heroku/python/lib/python2.7/site-packages/alembic/command.py", line 28, in init
raise util.CommandError("Directory %s already exists" % directory)
alembic.util.CommandError: Directory migrations already exists
manage.py:
app = create_app(os.environ.get('FLASK_CONFIG', 'default'))
magrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
@manager.command
def init_db():
db.drop_all()
db.create_all()
config.py:
class Config(object):
DEBUG = False
SECRET_KEY = 'Thisismysecretkey'
SQLALCHEMY_DATABASE_URI = os.environ.get(
'DATABASE_URL',
'postgresql+psycopg2://peg:1234@localhost/app')
print SQLALCHEMY_DATABASE_URI
class HerokuConfig(ProductionConfig):
def init_app(cls, app):
ProductionConfig.init_app(app)
import logging
from logging import StreamHandler
file_handler = StreamHandler()
file_handler.setLevel(logging.WARNING)
app.logger.addHandler(file_handler)
config = {
'development': DevelopmentConfig,
'testing': TestingConfig,
'production': ProductionConfig,
'heroku': HerokuConfig,
'default': DevelopmentConfig
}
答案 0 :(得分:4)
您似乎正在尝试再次运行manage.py db init
。不要这样做,迁移目录和迁移已经存在于您已经构建的应用程序中。而是运行manage.py db upgrade
。