我有 2 张桌子。表A和表B
TableA
+------+----------------+-----------+
| id | some_attribute | tableB_id |
+------+----------------+-----------+
id
=主键
some_attribute
=varchar
TableB_id
=外键
TableB
+------+----------------+
| id | some_attribute |
+------+----------------+
id
=主键
some_attribute
=varchar
我的代码:
# establish a connection with the database (MySQL)
db = Connection.Connection.connect_db_server_default()
class TableB(db.Entity):
_table_ = "table_b"
id = PrimaryKey(int, auto=False)
some_attribute = Required(str)
class TableA(db.Entity):
_table_ = "table_a"
id = PrimaryKey(int, auto=False)
some_attribute = Required(str)
TableB_id = Set(TableA)
给出以下错误:
pony.orm.core.ERDiagramError: Reverse attribute for TableA.TableB_id not found
我的问题:
如何使用 Pony ORM 重新创建上述关系?实体总是需要有双向关系吗?
有什么方法可以实现正确的数据库规范化,还是我必须使用一些不同的 ORM 模块?