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
-~----------~----~----~----~------~----~------~--~---

Reply via email to