2017-04-20 42 views
0

新的Python的世界,被推薦去嘗試cookiecutter-flask而是撞到一個問題:瓶18.11機型不產生遷移

我產生遷移「手動」而不是讓它基於模型。在我意識到可以使用模型來生成遷移(如使用cookiecutter進行「庫存」)之後,我刪除了手動遷移,但似乎無法使模型生成遷移文件。

在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' 

它似乎無法檢測類別模型,而我失去了我在這裏失蹤的內容?

回答

0

哦,所以這個問題最終是這樣的:

我根據我的隨附18.11的用戶模型的模型。在視圖中,我們從來沒有導入用戶模型,其中它顯然要進口的,而不是機制似乎依靠公共/ views.py在導入

from project.user.models import User 

而且由於register_blueprints()在公衆面前被加載時,我們已經在我們處理用戶視圖時可以訪問用戶模型。

所以TL,它需要醫生在whatevermodel/views.py導入爲

from project.category.models import Category 

這聽起來好像有點過分魔術和依賴於用戶之前加載公共福利...