小编Lin*_*nda的帖子

失败:找不到配置文件'alembic.ini'

我试图改变Alembic但是当我尝试运行Alembic时我得到了错误.我是alembic的新手,请告诉我为什么我会收到此错误,我该如何解决?

我可以alembic.ini在迁移文件夹和Alembic使用的修订标识符中看到,一切似乎都很好.

$alembic current
No handlers could be found for logger "alembic.util"
  FAILED: No config file 'alembic.ini' found, or file has no '[alembic]' section
Run Code Online (Sandbox Code Playgroud)

20c921506336_.py:

"""empty message

Revision ID: 20c921506336
Revises: None
Create Date: 2015-01-30 16:28:38.981023

"""

# revision identifiers, used by Alembic.
revision = '20c921506336'
down_revision = None

from alembic import op
import sqlalchemy as sa


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('user',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=50), nullable=True),
    sa.Column('email', …
Run Code Online (Sandbox Code Playgroud)

python alembic

12
推荐指数
2
解决办法
8689
查看次数

将数据库迁移从sqlalchemy-migrate更改为Flask-Migrate

我有一个基于miguel flask教程的Web应用程序

所以我使用sqlalchemy-migrate作为数据库,现在我应该在迁移中使用Alembic如何进行配置?有什么办法我可以从sqlalchemy-migrate更改为Flask-Migrate吗?(因为我的应用程序已经完成并且再次执行它是如此多的工作)Thanx

db_migrate.py:

#!flask/bin/python
import imp
from migrate.versioning import api
from app import db
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
migration = SQLALCHEMY_MIGRATE_REPO + '/versions/%03d_migration.py' % (api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) + 1)
tmp_module = imp.new_module('old_model')
old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
exec old_model in tmp_module.__dict__
script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)
open(migration, "wt").write(script)
api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
print 'New migration saved as ' + migration
print 'Current database version: ' + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO))
Run Code Online (Sandbox Code Playgroud)

python data-migration flask-sqlalchemy alembic flask-migrate

3
推荐指数
1
解决办法
2332
查看次数

UndefinedError:“ current_user”未定义

我有一个带有flask的应用程序,该应用程序之前可以工作,但是现在我在其中使用了Blueprint并尝试运行它,但是出现了错误,所以我想知道那是g.user无法使用的Blueprint问题吗?以及如何解决它Thnx :)

app / layout / __ init __.py:

from flask import Blueprint
layout = Blueprint('layout', __name__)
from . import view
Run Code Online (Sandbox Code Playgroud)

__初始化__ .py

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.login import LoginManager
import psycopg2
from config import basedir
from config import config

app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy()
lm = LoginManager()
lm.init_app(app)
lm.login_view = 'login'


def create_app(config_name):
    app = Flask(__name__)
    app.config['DEBUG'] = True
    app.config.from_object(config[config_name])
    db.init_app(app)
    from .layout import layout as appr_blueprint
    # register our …
Run Code Online (Sandbox Code Playgroud)

python jinja2 blueprint flask

3
推荐指数
1
解决办法
4322
查看次数

AttributeError:“列表”对象没有属性“ _sa_instance_state”

我收到以下错误,并且不确定如何解决。我认为这与is_bestfriend关系有关。

File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/local/lib/python2.7/dist-packages/flask_login.py", line 758, in decorated_view …
Run Code Online (Sandbox Code Playgroud)

python sqlalchemy flask

3
推荐指数
1
解决办法
4378
查看次数