Reputation: 524
Is there any way to use PonyORM for an existing database?
I have a table Test
in my db and I want to define an Entity Test
to connect to that table, I tried to use _table_ = 'Test'
and __table_name__ = 'Test'
like:
class Test(db.Entity):
__table_name__ = 'Test'
This allowed me to execute queries on table Test
, but I can't access table columns via Entity attributes (I guess because it does not load them from db automatically).
For example, when I try to create a new instance of Test
, I get:
Test(my_attr = 'Hello')
>>> TypeError: Unknown attribute 'my_attr'
I'm working on a Database First designed project and the database is changing constantly, so keep redefining columns in Entities seems like a bad solution.
Upvotes: 0
Views: 498
Reputation: 81
You must write columns to class. This way it can correctly link your database table to the class.
For example
class Test(db.Entity):
__table_name__ = 'Test'
my_attr = Optional(str)
Upvotes: 0