【发布时间】:2020-04-14 18:06:00
【问题描述】:
为什么这段代码会返回错误?
错误:初始化映射器 Mapper|Pessoa|pessoa 时,表达式 'Imovel' 未能找到名称(“名称 'Imovel' 未定义”)。
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
db=SQLAlchemy()
ma=Marshmallow()
class Pessoa(db.Model):
__tablename__ = 'pessoa'
idLocal= db.Column(db.Integer, primary_key=True)
Nome=db.Column(db.String(100), default=u'')
imovelList = db.relationship("Imovel", back_populates="PessoaList")
def get_id(self):
return self.idLocal
class PessoaSchema(ma.ModelSchema):
class Meta: model = Pessoa
class Imovel(db.Model):
__tablename__ = 'imovel'
idLocal= db.Column(db.Integer, primary_key=True)
CodigoImovel=db.Column(db.String(30), default=u'')
idPessoa = db.Column(db.Integer, db.ForeignKey('pessoa.idLocal'))
PessoaList = db.relationship("Pessoa", back_populates="imovelList")
def get_id(self):
return self.idLocal
class ImovelSchema(ma.ModelSchema):
class Meta: model = Imovel
【问题讨论】:
-
也许可以尝试在课后移动
PessoaSchemaImovel
标签: python flask sqlalchemy marshmallow