Reputation: 1564
Python 3.11, pony 0.7.17: I run my PonyORM setup code in this __init __.py
from pony import orm
db = orm.Database()
def startup_database():
db.bind(
provider="postgres",
user="...",
password="...",
host="localhost",
database="...",
port="5432",
)
orm.sql_debug(True)
def main():
startup_database() # If you have another methods, THIS LINE SHOULD BE THE LAST ONE
if __name__ == "__main__":
main()
Then a User Entity is defined in another user.py module like this:
from pony.orm import *
db = Database()
class User(db.Entity):
firstname = Required(str)
lastname = Required(str)
email = Required(str)
...
db.generate_mapping(create_tables=True)
However, running that code gives me this error: pony.orm.core.MappingError: Database object is not bound with a provider yet
initiated by the user.py > db.generate_mapping(create_tables=True) but binding already happened in the __init __.py > startup_database() function - right?
Upvotes: 0
Views: 92