我有两个型号
在users / models.py
中class User(db.Model):
__tablename__ = 'users'
id = db.Column('id', db.Integer, primary_key=True)
feedbacks = db.relationship(
'Feedback', backref='user', lazy='select')
以units / models.py
表示class Feedback(db.Model):
__tablename__ = 'feedbacks'
id = db.Column('id', db.Integer, primary_key=True)
author_id = db.Column('author_id', db.ForeignKey('users.id'))
架构引发错误:
Traceback (most recent call last):
File "manage.py", line 9, in <module>
from main import app, db
File "/home/iromanov/work/sqvr/src/main.py", line 62, in <module>
app = create_app()
File "/home/iromanov/work/sqvr/src/main.py", line 54, in create_app
create_admin_panel(app_name, admin_manager, db)
File "/home/iromanov/work/sqvr/src/admins.py", line 38, in create_admin_panel
category=app_name.capitalize())
File "/home/iromanov/work/sqvr/src/admins.py", line 22, in __init__
model, session, name, category, endpoint, url)
File "/home/iromanov/.virtualenvs/sqvr/local/lib/python2.7/site-packages/flask_admin/contrib/sqla/view.py", line 271, in __init__
super(ModelView, self).__init__(model, name, category, endpoint, url)
File "/home/iromanov/.virtualenvs/sqvr/local/lib/python2.7/site-packages/flask_admin/model/base.py", line 515, in __init__
self._refresh_cache()
File "/home/iromanov/.virtualenvs/sqvr/local/lib/python2.7/site-packages/flask_admin/model/base.py", line 523, in _refresh_cache
self._list_columns = self.get_list_columns()
File "/home/iromanov/.virtualenvs/sqvr/local/lib/python2.7/site-packages/flask_admin/model/base.py", line 644, in get_list_columns
columns = self.scaffold_list_columns()
File "/home/iromanov/.virtualenvs/sqvr/local/lib/python2.7/site-packages/flask_admin/contrib/sqla/view.py", line 322, in scaffold_list_columns
for p in self._get_model_iterator():
File "/home/iromanov/.virtualenvs/sqvr/local/lib/python2.7/site-packages/flask_admin/contrib/sqla/view.py", line 293, in _get_model_iterator
return model._sa_class_manager.mapper.iterate_properties
File "/home/iromanov/.virtualenvs/sqvr/local/lib/python2.7/site-packages/sqlalchemy/orm/mapper.py", line 1797, in iterate_properties
configure_mappers()
File "/home/iromanov/.virtualenvs/sqvr/local/lib/python2.7/site-packages/sqlalchemy/orm/mapper.py", line 2583, in configure_mappers
mapper._post_configure_properties()
File "/home/iromanov/.virtualenvs/sqvr/local/lib/python2.7/site-packages/sqlalchemy/orm/mapper.py", line 1688, in _post_configure_properties
prop.init()
File "/home/iromanov/.virtualenvs/sqvr/local/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.py", line 144, in init
self.do_init()
File "/home/iromanov/.virtualenvs/sqvr/local/lib/python2.7/site-packages/sqlalchemy/orm/relationships.py", line 1549, in do_init
self._process_dependent_arguments()
File "/home/iromanov/.virtualenvs/sqvr/local/lib/python2.7/site-packages/sqlalchemy/orm/relationships.py", line 1605, in _process_dependent_arguments
self.target = self.mapper.mapped_table
File "/home/iromanov/.virtualenvs/sqvr/local/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 725, in __get__
obj.__dict__[self.__name__] = result = self.fget(obj)
File "/home/iromanov/.virtualenvs/sqvr/local/lib/python2.7/site-packages/sqlalchemy/orm/relationships.py", line 1522, in mapper
argument = self.argument()
File "/home/iromanov/.virtualenvs/sqvr/local/lib/python2.7/site-packages/sqlalchemy/ext/declarative/clsregistry.py", line 278, in __call__
(self.prop.parent, self.arg, n.args[0], self.cls)
sqlalchemy.exc.InvalidRequestError: When initializing mapper Mapper|User|users, expression u'Vote' failed to locate a name ("name 'Feedback' is not defined"). If this is a class name, consider adding this relationship() to the <class 'users.models.User'> class after both dependent classes have been defined.
但如果我将反馈导入添加到users.models.py,我有错误:
Traceback (most recent call last):
File "manage.py", line 9, in <module>
from main import app, db
File "/home/iromanov/work/sqvr/src/main.py", line 62, in <module>
app = create_app()
File "/home/iromanov/work/sqvr/src/main.py", line 54, in create_app
create_admin_panel(app_name, admin_manager, db)
File "/home/iromanov/work/sqvr/src/admins.py", line 38, in create_admin_panel
category=app_name.capitalize())
File "/home/iromanov/.virtualenvs/sqvr/local/lib/python2.7/site-packages/flask_admin/base.py", line 424, in add_view
self.app.register_blueprint(view.create_blueprint(self))
File "/home/iromanov/.virtualenvs/sqvr/local/lib/python2.7/site-packages/flask/app.py", line 62, in wrapper_func
return f(self, *args, **kwargs)
File "/home/iromanov/.virtu`enter code here`alenvs/sqvr/local/lib/python2.7/site-packages/flask/app.py", line 885, in register_blueprint
(blueprint, self.blueprints[blueprint.name], blueprint.name)
AssertionError: A blueprint's name collision occurred between <flask.blueprints.Blueprint object at 0x7f5bacd66610> and <flask.blueprints.Blueprint object at 0x7f5bacfa7710>. Both share the same name "voteview". Blueprints that are created on the fly need unique names.
如果需要更多信息,请问我。
如果我在用户模型体中导入反馈,那么所有工作,但我认为这不是很酷。