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
}
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With