Flask-Migrate错误:' ConfigParser.NoSection错误:没有部分:' alembic''

时间:2015-10-25 20:51:40

标签: python flask alembic flask-migrate

在过去的几周里,我一直在建立一个网站,主要基于Miguel Grinberg的书“Flask Web Development'”。这是我的'manage.py'文件供参考:

import os
from app import create_app, db
from app.models import User, Role, Permission, Post
from flask.ext.script import Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)
migrate = Migrate(app, db)

def make_shell_context():
    return dict(app=app, db=db, User=User, Follow=Follow, Role=Role,
                Permission=Permission, Post=Post)

manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)

if __name__ == '__main__':
     manager.run()

这是我的app / __ init.py文件:

from flask import Flask #session, flash, url_for
from flask.ext.mail import Mail
from flask.ext.moment import Moment
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.login import LoginManager
from config import config

login_manager = LoginManager()
login_manager.session_protection = 'strong'
login_manager.login_view = 'auth.login'

mail = Mail()
moment = Moment()
db = SQLAlchemy() 

def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)

    login_manager.init_app(app)
    mail.init_app(app)
    moment.init_app(app)
    db.init_app(app)

    from main import main as main_blueprint
    from .auth import auth as auth_blueprint
    app.register_blueprint(main_blueprint)
    app.register_blueprint(auth_blueprint, url_prefix = '/auth')

    return app

正如你所看到的那样,这是一个相对简单的项目,但是直到几天前我才意外地删除了我的迁移文件夹,直到那时我的工作都没有完全正常。当我再次尝试设置迁移文件夹时,出现此错误:

(website1)joshua@joshua-ThinkPad-Edge-E430 ~/website/website1 $ python manage.py db migrate
Traceback (most recent call last):
  File "manage.py", line 29, in <module>
    manager.run()
  File "/home/joshua/.virtualenvs/website1/lib/python2.7/site-packages/flask_script/__init__.py", line 412, in run
    result = self.handle(sys.argv[0], sys.argv[1:])
  File "/home/joshua/.virtualenvs/website1/lib/python2.7/site-packages/flask_script/__init__.py", line 383, in handle
    res = handle(*args, **config)
  File "/home/joshua/.virtualenvs/website1/lib/python2.7/site-packages/flask_script/commands.py", line 216, in __call__
    return self.run(*args, **kwargs)
  File "/home/joshua/.virtualenvs/website1/lib/python2.7/site-packages/flask_migrate/__init__.py", line 153, in migrate
    config = _get_config(directory, opts=['autogenerate'])
  File "/home/joshua/.virtualenvs/website1/lib/python2.7/site-packages/flask_migrate/__init__.py", line 51, in _get_config
    config.set_main_option('script_location', directory)
  File "/home/joshua/.virtualenvs/website1/lib/python2.7/site-packages/alembic/config.py", line 201, in set_main_option
    self.file_config.set(self.config_ini_section, name, value)
  File "/home/joshua/anaconda/lib/python2.7/ConfigParser.py", line 753, in set
    ConfigParser.set(self, section, option, value)
  File "/home/joshua/anaconda/lib/python2.7/ConfigParser.py", line 396, in set
    raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'alembic'

我不确定该如何处理,我已尝试删除然后重新创建我的数据库并再次运行db migrate但我得到了和以前一样的错误。我也试过卸载并重新安装alembic,但没有运气。

我不确定此时做了什么,到目前为止,每当我遇到教程问题时,我都花时间自己解决这个问题,因为我想了解如何一切正常,但我完全不知道这一点。

1 个答案:

答案 0 :(得分:0)

礼貌Dauros:我忽略了运行python manage.py db init。