Flask cookiecutter 模型不生成迁移
Flask cookiecutter models don't generate migrations
python 的新手,被推荐尝试 cookiecutter-flask 但遇到了一个问题:
我生成了一个迁移 "manually" 而不是基于模型。在我意识到模型可以用来生成像 cookiecutter "stock" 附带的那样的迁移之后 - 我删除了我的手动迁移但似乎无法让模型生成迁移文件。
在app.py
from project import commands, public, user, category
def register_blueprints(app):
"""Register Flask blueprints."""
app.register_blueprint(public.views.blueprint)
app.register_blueprint(user.views.blueprint)
app.register_blueprint(category.views.blueprint) <- my model
return None
在浏览量中
blueprint = Blueprint('category', __name__, url_prefix='/categories', static_folder='../static')
我的路线似乎被检测到
#flask urls
/categories/ category.categories
/categories/static/<path:filename> category.static
但是当我运行
#flask db migrate
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.autogenerate.compare] Detected added table 'users'
INFO [alembic.autogenerate.compare] Detected added table 'roles'
它似乎无法检测类别模型,我不知道我在这里遗漏了什么?
哦,原来问题是这样的:
我的模型基于 cookiecutter 附带的用户模型。在我们看来,我们从来没有在显然应该导入的地方导入用户模型,相反,该机制似乎依赖于 public/views.py 导入它
from project.user.models import User
并且因为在 register_blueprints() public 之前加载,我们在处理用户视图时已经可以访问用户模型。
所以 tl;dr 它需要在 whatevermodel/views.py 中导入为
from project.category.models import Category
这对我来说听起来有点太神奇了,并且依赖于 public 在用户之前加载...
python 的新手,被推荐尝试 cookiecutter-flask 但遇到了一个问题:
我生成了一个迁移 "manually" 而不是基于模型。在我意识到模型可以用来生成像 cookiecutter "stock" 附带的那样的迁移之后 - 我删除了我的手动迁移但似乎无法让模型生成迁移文件。
在app.py
from project import commands, public, user, category
def register_blueprints(app):
"""Register Flask blueprints."""
app.register_blueprint(public.views.blueprint)
app.register_blueprint(user.views.blueprint)
app.register_blueprint(category.views.blueprint) <- my model
return None
在浏览量中
blueprint = Blueprint('category', __name__, url_prefix='/categories', static_folder='../static')
我的路线似乎被检测到
#flask urls
/categories/ category.categories
/categories/static/<path:filename> category.static
但是当我运行
#flask db migrate
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.autogenerate.compare] Detected added table 'users'
INFO [alembic.autogenerate.compare] Detected added table 'roles'
它似乎无法检测类别模型,我不知道我在这里遗漏了什么?
哦,原来问题是这样的:
我的模型基于 cookiecutter 附带的用户模型。在我们看来,我们从来没有在显然应该导入的地方导入用户模型,相反,该机制似乎依赖于 public/views.py 导入它
from project.user.models import User
并且因为在 register_blueprints() public 之前加载,我们在处理用户视图时已经可以访问用户模型。
所以 tl;dr 它需要在 whatevermodel/views.py 中导入为
from project.category.models import Category
这对我来说听起来有点太神奇了,并且依赖于 public 在用户之前加载...