The problem is in line 61 of your db.py.

When you make "Field('student', db.student", you are telling the DAL
to go look for a table named "student."  If you have no such table, it
will raise an exception.

If you're going to do a self join, the right syntax would be
"Field('student', db.auth_user"

Somewhere Massimo (I think it was him) has written about self joins,
but I don't recall where... Sorry I can't point you to a reference.

On Aug 8, 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

Reply via email to