pythonponyorm

Sharing PonyORM's db session across different python module


I initially started a small python project (Python, Tkinter amd PonyORM) and became larger that is why I decided to divide the code (used to be single file only) to several modules (e.g. main, form1, entity, database). Main acting as the main controller, form1 as an example can contain a tkinter Frame which can be used as an interface where the user can input data, entity contains the db.Enttiy mappings and database for the pony.Database instance along with its connection details. I think problem is that during import, I'm getting this error "pony.orm.core.ERDiagramError: Cannot define entity 'EmpInfo': database mapping has already been generated". Can you point me to any existing code how should be done.


Solution

  • Probably you import your modules in a wrong order. Any module which contains entity definitions should be imported before db.generate_mapping() call.

    I think you should call db.generate_mapping() right before entering tk.mainloop() when all imports are already done.