table 'roles_users' is already defined for this MetaData instance

前端 未结 11 979
执笔经年
执笔经年 2021-02-05 01:40

hello iam trying to get a currnet_user information in my views

and i include from users.models import *

then in my code return return current_user;

<         


        
11条回答
  •  一向
    一向 (楼主)
    2021-02-05 02:28

    TL;DR

    • If you encounter this error when trying to register flask blueprint to application, check if Model importing path is consistent across all blueprints where imports the Model

    For example

    • Blueprint 1: from A.B.C import Model A
    • Blueprint 2: from .B.C import Model A (This raises error, importing path should be consistent across all blueprints that imports the same model. So it should be from A.B.C import Model A)

    I haven't dig this issue to find out what is the cause, but I guess that SQLAlchemy manages Model with its imported namespace and raise error when different namespace is defined but the models are same.

提交回复
热议问题