Is 'Container' a Reserved Word?

27 views
Skip to first unread message

Brian Boatright

unread,
Aug 28, 2016, 8:41:17 PM8/28/16
to web2py-users
I've tried adding a model for "Containers" and "ContainerTypes" each time I get an error when it tries to create the tables when I click the Database Admin button.

The other tables I'm defining are working fine. I have a few other tables that have "Type" in their mode/table name so when I couldn't create "containers" table.

I've looked at MySQL and MariaDB (which I'm using) and do not see "container" or something similar listed as a reserved word. 

here is the error

<type 'exceptions.NameError'> name 'db' is not defined

db.define_table('containers',
   
Field('parentid','reference containers'),
    Field('name','string'))

Traceback (most recent call last):
  File "C:\dev\web2py\gluon\restricted.py", line 227, in restricted
    exec ccode in environment
  File "C:/dev/web2py/applications/partsbin/models/containers.py", line 2, in <module>
    db.define_table('containers',
NameError: name 'db' is not defined

Anthony

unread,
Aug 28, 2016, 9:59:01 PM8/28/16
to web2py-users
That's not the error you would get if you were using a reserved word. The problem is that at that point in the code execution, the db object has not been defined. Note, when you click the database admin button, the appadmin.py controller is executed. Is your db object defined in another controller (rather than in a model file)? It's hard to say what's going on without seeing more code.

Anthony

Brian Boatright

unread,
Aug 29, 2016, 8:47:39 AM8/29/16
to web...@googlegroups.com
Thanks Anthony!

All the db tables were defined in separate model files, which is what I would prefer, but as a last attempt to resolve the conflict I moved them all to a single models.py model file and arranged a few of the declarations to avoid that error. It is working now but I would have preferred the models in separate files, but maybe that's not possible when they have so many foreign keys. 

Is it possible to stage the order which the model files are read so table declarations will be in the right sequence

Anthony

unread,
Aug 29, 2016, 10:04:44 AM8/29/16
to web2py-users
There should be no problem spreading your table definitions over multiple model files. However, the db object itself must be defined in a model file that is executed before any other model files in which tables are defined. You could name that model file something like 0.py to ensure it runs before any other model files (model files are executed in alphabetical order).

Anthony
Reply all
Reply to author
Forward
0 new messages