Thanks Massimo, but doesn't migrate=False prevent me from altering the table's structure within a running instance of web2py? Your manual says:
"When a table is defined web2py takes one of several possible actions: a) if the table does not exist the table is created; b) if the table exists and does not correspond to the definition, the table is altered accordingly, and if a field has a different type, web2py tries to convert its content; c) if the table exists and corresponds to the definition, it does nothing. This behavior is called "migration". In web2py migrations are au- tomatic but they can be disabled for each individual table by passing migrate=False as last argument of define table." It seems to me that migrate=True, as described above, is exactly what I want while the table is under development. Or am I misunderstanding what migrate=False does? I'm assuming it means the table will be dropped with all its data and a new one will be created? Thanks, Mike On Jun 30, 11:11 am, mdipierro <mdipie...@cs.depaul.edu> wrote: > db.define_table('config', ...., migrate=False) > > do not put the define_table in a try catch. You may end up with an > incomplete table definition. > > Massimo > > On Jun 30, 9:52 am, MikeEllis <michael.f.el...@gmail.com> wrote: > > > See the "table exists" discussions for background. > > > I'm trying to get around the problem by using a try/except but it > > seems like the error type that's raised isn't defined until after the > > error is raised. > > > So calling define_table without the try/except gives > > > Traceback (most recent call last): > > File "/Users/mellis/sources/trunk/python/web2py/gluon/ > > restricted.py", line 107, in restricted > > exec ccode in environment > > File "/Users/mellis/sources/trunk/python/web2py/applications/init/ > > models/db.py", line 67, in <module> > > db.define_table('config', *args, **kwargs) > > < --- SNIP ---> > > File "/Users/mellis/sources/trunk/python/web2py/gluon/sql.py", line > > 697, in <lambda> > > self._execute = lambda *a, **b: self._cursor.execute(*a, **b) > > OperationalError: table config already exists > > > but if I code it as > > > try: > > db.define_table('config', *args, **kwargs) > > except OperationalError: > > logging.error("Ignoring OperationalError from define_table()") > > > I get the following: > > > Traceback (most recent call last): > > File "/Users/mellis/sources/trunk/python/web2py/gluon/ > > restricted.py", line 107, in restricted > > exec ccode in environment > > File "/Users/mellis/sources/trunk/python/web2py/applications/init/ > > models/db.py", line 68, in <module> > > except OperationalError: > > NameError: name 'OperationalError' is not defined > > > I can avoid the error by using a bare except clause, but that's really > > awful coding style because it suppresses all errors. > > > Anybody have a better workaround for this? > > > Thanks, > > Mike > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---