"Directory migrations already exists" 在 Heroku 初始化期间

"Directory migrations already exists" during init on Heroku

我 运行 命令 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
}

您似乎想再次 运行 manage.py db init。不要那样做,迁移目录和迁移已经存在于您已经构建的应用程序中。相反,运行 manage.py db upgrade.