-
Notifications
You must be signed in to change notification settings - Fork 246
Open
Description
My idea is that some fields exist in all tables, such as: creation time, update time, deletion time, etc. I want to achieve coding efficiency through model class inheritance. But I got the following error: pony.orm.core.ERDiagramError: Base Entity does not belong to any database.
Please help me see or give some suggestions, thank you very much!
# main.py
from pony import orm
from datetime import datetime
orm.set_sql_debug(True)
db = orm.Database()
db.bind(
provider='mysql',
host='127.0.0.1',
user='root',
passwd='secret',
db='demo'
)
class Entity(db.Entity):
created_at = orm.Optional(datetime)
updated_at = orm.Optional(datetime)
class Podcast(Entity):
_table_ = "podcasts"
id = orm.PrimaryKey(int, auto=True)
bid = orm.Required(int)
title = orm.Required(str)
cover = orm.Optional(str)
sequence = orm.Optional(int)
db.generate_mapping(create_tables=False, check_tables=False)
with orm.db_session as s:
p = Podcast[1]
print(p)
$ uv run main.py
================ ERROR ================
GET NEW CONNECTION
RELEASE CONNECTION
Traceback (most recent call last):
File "/fake/dir/main.py", line 17, in <module>
class Podcast(Entity):
File "/fake/dir/.venv/lib/python3.12/site-packages/pony/orm/core.py", line 3700, in __init__
if database is None: throw(ERDiagramError, 'Base Entity does not belong to any database')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/fake/dir/.venv/lib/python3.12/site-packages/pony/utils/utils.py", line 99, in throw
raise exc
pony.orm.core.ERDiagramError: Base Entity does not belong to any database
Metadata
Metadata
Assignees
Labels
No labels