I did what you said but I still have an error... db.define_table('tableX', ....) auth.settings.extra_fields['auth_user'] = [Field('myFK_id', 'reference tableX')] auth.define_tables()
InternalError: (1072, u"Key column 'myFK_id' doesn't exist in table") Why ? On Oct 26, 7:37 am, Cliff <cjk...@gmail.com> wrote: > Why not define tableX before auth.define_tables? > > I'm doing that with a table and it seems to work. Caveat: there's no > controller for that table so it only gets exposed to the site owner. > > On Oct 25, 8:44 am, Massimo Di Pierro <massimo.dipie...@gmail.com> > wrote: > > > this will work > > > auth.settings.extra_fields['auth_user'] = [Field('myFK_id', 'reference > > tableX')] > > > You cannot use db.tableX because that is not yet defined. > > On Oct 25, 12:20 am, Alex <dalfga...@gmail.com> wrote: > > > > Hi, > > > I have a simple question : I would like to add a foreign key to the > > > table auth_user, but I don't know how to do that. > > > I can add a text field easily. For example : > > > > auth = Auth(db) > > > auth.settings.extra_fields['auth_user'] = [Field('city')] > > > auth.define_tables() > > > > But if I do this, it doesn't work: > > > > auth = Auth(db) > > > auth.settings.extra_fields['auth_user'] = [Field('myFK_id', > > > db.tableX)] > > > auth.define_tables() > > > > db.define_table('tableX', .....) > > > > I can't find anything on the Web... > >