Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Directory migrations already exists" during init on Heroku

I ran the command heroku run init and got this error. How can I fix it?

 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
}
like image 698
LiLi Avatar asked Feb 10 '23 17:02

LiLi


1 Answers

You appear to be trying to run manage.py db init again. Don't do that, the migration directory and migrations already exist in the application you've already built. Instead, run manage.py db upgrade.

like image 58
davidism Avatar answered Feb 13 '23 05:02

davidism