Thanks for your response, Richard and Jim. Richard, the traceback is in my original message, as is the problematic part of the model code. The error occurs with any view/controller -- I can't access the app at all. The problem is definitely in the model and not the controller. The problem occurs when I insert any code into a model with the following syntax:
field('fieldname", db.referenced_table) The error is revealed at the end of the traceback included in my original message: KeyError: 'student' One thing that confused me when reading the web2py book was the relatively brief time spend discussing foreign key relationships. Every other framework I've used (CakePHP and symfony) has spent at least a full chapter describing how to set up these relationships in the models. This makes me feel like I'm missing something really obvious. web2py has surprised me by letting me finish tasks that were very time consuming in other frameworks in a few lines of code, so I'm wondering if there's a really simple way to describe one-to-many and many-to-many relationships in web2py that I'm missing in the documentation. This is the syntax used for referencing many-to-one relationships in Chapter 7 of the latest web2py book, so I'm not entirely sure what I'm doing wrong. Jim, there is a many-to-one relationship between both students:users and contacts:users. I'm not sure if that's what you're asking. I've not seen the code you use anywhere in the web2py book (at least not that I recall), so I will give it a try to see if it works. Thanks again, Eric On Aug 8, 3:58 pm, Richard Vézina <ml.richard.vez...@gmail.com> wrote: > If you send you controller and model code at least with trace back it could > help to troobleshoot... > > Richard > > > > > > > > On Mon, Aug 8, 2011 at 3:51 PM, Eric Scott <erictransla...@gmail.com> wrote: > > I'm having problems getting tables linked in web2py using reference > > fields. For example, I have a model with table student and table > > contact. Table auth_user contains my app's users. In db.py, under > > db.define_table('auth_user') I have the following code to reference a > > one-to-many relationship between users:students and users:contacts: > > > Field('student', db.student), > > Field('contact', db.contact), > > > But I keep getting the following error: > > > Traceback (most recent call last): > > File "/home/www-data/web2py/gluon/restricted.py", line 192, in > > restricted > > exec ccode in environment > > File "/home/www-data/web2py/applications/teachertext/models/db.py", > > line 61, in <module> > > Field('student', db.student, > > File "/home/www-data/web2py/gluon/dal.py", line 4331, in __getattr__ > > return self[key] > > File "/home/www-data/web2py/gluon/dal.py", line 4325, in __getitem__ > > return dict.__getitem__(self, str(key)) > > KeyError: 'student' > > > I'm new to web2py (but not to frameworks) and this is my first time > > referencing foreign keys in a web2py app. I'm sure I'm missing > > something obvious but I'd be grateful if someone could point it out > > for me. > > > Thank you, > > > Eric