其目的是让两个简单的类表示数据库中已经存在的两个相关表。
代码是:
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)
我试图遵循我见过的in the documentation方法,但是执行上面的代码会给我带来:
psycopg2.ProgrammingError: column structures.system does not exist
LINE 1: ...ctures"."structure_id", "structures"."system_id", "structure...HINT: Perhaps you meant to reference the column "structures.system_id".
这里少了什么?在
使用Pony,您不需要为
system_id
和system
创建两个单独的属性。相反,您需要将system_id
指定为属性system
的列。默认情况下,Pony假定列名等于属性名。那么Structure
类将如下例所示:相关问题 更多 >
编程相关推荐