를 추가 할 때 'NoneType'개체 오류 'filter_by'에는 속성이 없습니다. OrderModel
과 두 클래스 간의 관계를 추가 할 때까지 모든 것이 잘 동작합니다. UserModel
또는 ChefModel
에 대한 모든 호출에서 다음 오류가 발생합니다. 예를 들어, 내가하려고 할 때 요리사를 찾을 수 있습니다 :플라스크-SQLAlchemy의 : 나는 내 DB에 대한 다음과 같은 구조를 만들기 위해 노력하고 관계
class ChefModel(UserModel):
__tablename__ = 'chefs'
id = db.Column(db.Integer, db.ForeignKey('users.id'), primary_key = True)
food_items = db.relationship("FoodItemModel", backref="chef", lazy=True)
__mapper_args__ = {'polymorphic_identity':'chefs'}
CustomerModel :
class CustomerModel(UserModel):
__tablename__ = 'customers'
id = db.Column(db.Integer, db.ForeignKey('users.id'), primary_key = True)
__mapper_args__ = {'polymorphic_identity':'customers'}
그리고 OrderModel : 여기
File "C:\Users\Moham\Documents\Food order\resources\chef.py", line 60, in get
users = ChefModel.query.filter_by(active = True).all()
AttributeError: 'NoneType' object has no attribute 'filter_by'
내 ChefModel입니다
class OrderModel(db.Model):
__tablename__ = 'orders'
order_id = db.Column(db.Integer, primary_key = True)
updated_date = db.Column(db.DateTime, default=datetime.utcnow())
description = db.Column(db.String(254))
food_items = db.relationship("FoodItemModel", secondary = association_table)
customer_id = db.relationship(db.Integer, db.ForeignKey('customers.id')) //if remove this line
chef_id = db.relationship(db.Integer, db.ForeignKey('chefs.id')) //and this line, calls are normal
무엇 내가 틀렸어?
아마도 필터에 문제가 있습니까? 'users = ChefModel.query.filter (ChefModel.active.is_ (참)). all()' – Arunmozhi
'UserModel' 기본 클래스는 어떻게 생겼습니까? – bow