pony.orm.core.erdiagramerror:不一致的反向属性

问题描述 投票:0回答:2

当在Pony Ormm上指定我的桌子时,我会遇到此错误。

File "business.py", line 79, in <module> db.generate_mapping() File "<string>", line 2, in generate_mapping File "/home/ancinedev/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pony/utils/utils.py", line 58, in cut_traceback return func(*args, **kwargs) File "/home/ancinedev/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pony/orm/core.py", line 724, in generate_mapping entity._link_reverse_attrs_() File "/home/ancinedev/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pony/orm/core.py", line 3511, in _link_reverse_attrs_ throw(ERDiagramError, 'Inconsistent reverse attributes %s and %s' % (attr, attr2)) File "/home/ancinedev/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pony/utils/utils.py", line 96, in throw raise exc pony.orm.core.ERDiagramError: Inconsistent reverse attributes Pais.pessoas and Pessoa.identificador
我的pessoa表的属性称为cd_pais,此属性是对PAIS表的引用,在其中将其设置为主要键。
class Pais(db.Entity): _table_ = ['SAD', 'TA_PAIS'] codigo = PrimaryKey(int, column="CD_PAIS") nome = Required(str, column="NM_PAIS") pessoas = Set(lambda: Pessoa, reverse="identificador") class Pessoa(db.Entity): _table_ = ['SAD', 'TB_PESSOA'] identificador = PrimaryKey(int, column="ID_PESSOA") nome = Required(str, column="NM_PESSOA") tipo_pessoa = Required(str, column="IN_TIPO_PESSOA") numero_registro = Optional(str, column="NR_REGISTRO") pais = Required(Pais, reverse="codigo")

我尝试了许多文档和方式,但并没有成功。
	

代码段的问题是,您错误地将

reverse
python orm ponyorm
2个回答
1
投票
pessoas

实体中的

Pais
属性应该是
pais
实体中的
Pessoa
属性:
class Pais(db.Entity):
    _table_ = ['SAD', 'TA_PAIS']
    codigo = PrimaryKey(int, column="CD_PAIS")
    nome = Required(str, column="NM_PAIS")
    pessoas = Set(lambda: Pessoa, reverse="pais")

class Pessoa(db.Entity):
    _table_ = ['SAD', 'TB_PESSOA']
    identificador = PrimaryKey(int, column="ID_PESSOA")
    nome = Required(str, column="NM_PESSOA")
    tipo_pessoa = Required(str, column="IN_TIPO_PESSOA")
    numero_registro = Optional(str, column="NR_REGISTRO")
    pais = Required(Pais, reverse="pessoas")
但是在此示例中,指定

reverse
属性不是必需的,因为小马可以找出关系属性本身。只有在实体与自动关系之间建立一个关系之间的关系更多的情况下,才需要指定
reverse

如果您从实体声明中删除
reverse
,则可以正常工作:

class Pais(db.Entity): _table_ = ['SAD', 'TA_PAIS'] codigo = PrimaryKey(int, column="CD_PAIS") nome = Required(str, column="NM_PAIS") pessoas = Set(lambda: Pessoa) class Pessoa(db.Entity): _table_ = ['SAD', 'TB_PESSOA'] identificador = PrimaryKey(int, column="ID_PESSOA") nome = Required(str, column="NM_PESSOA") tipo_pessoa = Required(str, column="IN_TIPO_PESSOA") numero_registro = Optional(str, column="NR_REGISTRO") pais = Required(Pais)

there您可以找到有关实体关系的更多信息:
https://docs.ponyorm.com/relationships.html

此外,您可能还需要使用在线实体关系图编辑器

https://editor.ponyorm.com/。它可以帮助您为应用程序进行数据建模。

问题是生成SQL时。 File "/home/dev/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pony/orm/dbapiprovider.py", line 55, in wrap_dbapi_exceptions except dbapi_module.DatabaseError as e: raise DatabaseError(e) pony.orm.dbapiprovider.DatabaseError: ORA-00904: "TB_PESSOA"."PAIS": invalid identifier SELECT "TB_PESSOA"."ID_PESSOA", "TB_PESSOA"."NM_PESSOA", "TB_PESSOA"."IN_TIPO_PESSOA", "TB_PESSOA"."NR_REGISTRO", "TB_PESSOA"."PAIS" FROM "SAD"."TB_PESSOA" "TB_PESSOA" WHERE 0 = 1 pais实际上不存在PAIS,它实际上是一个名为CD_PAI的字段,是TA_PAIS的外键。


0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.