I have being there :-/ ... what i do was: 1.- Pass your models definitions to models and packages on ``modules`` 2.- In the modules put each table definition on a method, for example:
define_tables(): db = current.db if not hasattr(db, 'some_table'): db.define_table('some_table', ....) 3.- then whenever a some_other_table depends on some_table, in the module corresponding to some_other_table you import the corresponding define_tables of some_table and call it to ensure it get defined before some_other_table references it. 4.- use conditional models, and in the conditional model of a given controller you import and call only the one you need. This way, the imports and define_tables ensure the table definitions precedences and work out the needed for you.... the downside of passing models definitions to modules is that u need to reload the complete web2py instance... hence, if you are running it trough apache it must be restarted for changes to refresh. Regards, 2017-01-26 7:28 GMT-05:00 Bentorey Hernández Cruz <bentore...@gmail.com>: > Hi all, > I have a question related to table definitions in modules. I'm working > in an app that has more than a hundred tables and I noticed that even using > lazy tables it took too much for browsing the site. > I decided to move some of the tables to a module and call them on > demand, and the performance improved a lot. > The problem is if there's any way to define new tables from the module. > > Whatever I do, I get the error: > > ProgrammingError: ('ERROR', '42P01', 'relation "test_t" does not exist') > > Definition of test_t in module >> >> from gluon import * >> from gluon.dal import Field >> def defineTEST(db): >> if 'test_t' not in db: >> db.define_table('test_t', >> Field('bid', 'reference b_t', ondelete='CASCADE'), >> Field('date', 'date'), >> migrate=app_settings.migrate) > > > Code added to 10dbmodel.py in models: >> >> from app.modules import defineTEST >> defineTEST(db) > > > And the table is not created. > > Thank you! > > -- > Resources: > - http://web2py.com > - http://web2py.com/book (Documentation) > - http://github.com/web2py/web2py (Source code) > - https://code.google.com/p/web2py/issues/list (Report Issues) > --- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to web2py+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- Yoel Benítez Fonseca http://redevil.cubava.cu/ $ python -c "import this" -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.