Python pony.orm中与create_tables=False的关系

Python pony.orm中与create_tables=False的关系,python,database-first,ponyorm,Python,Database First,Ponyorm,目的是要有两个简单的类来表示数据库中已经存在的两个相关表。 代码是: from pony.orm import * db = Database() class System(db.Entity): _table_ = 'some', 'systems' system_id = PrimaryKey(int, auto=True) structures = Set('Structure') class Structure(db.Entity): _ta

目的是要有两个简单的类来表示数据库中已经存在的两个相关表。 代码是:

from pony.orm import *
db = Database()

class System(db.Entity):
    _table_ = 'some', 'systems'
    
    system_id = PrimaryKey(int, auto=True)
    structures = Set('Structure')

class Structure(db.Entity):
    _table_ = 'some', 'structures'
    structure_id = PrimaryKey(int, auto=True)
    system_id = Required(int)
    system = Required(System)

db.bind(...)
db.generate_mapping(create_tables=False)
我曾尝试采用我见过的方法,但执行上面的代码会让我:

psycopg2.ProgrammingError:列结构.system不存在 第1行:…ctures.structure\u id,structures.system\u id,structure

提示:可能您想引用列structures.system\u id


这里缺少什么?

对于Pony,您不会为system_id和system创建两个单独的属性。相反,您需要将system_id指定为属性system的列。默认情况下,Pony假定列名等于属性名。然后,结构类将如以下示例所示:

类Structuredb.Entity: _表=“某些”、“结构” 结构\u id=PrimaryKeyint,auto=True system=RequiredSystem,column='system\u id'