db.users.team.requires = IS_IN_DB(db, 'dogs.teamname', '%
(dogs.teamname)')

should be

db.users.team.requires = IS_IN_DB(db, 'dogs.teamname', '%
(teamname)s')

On Dec 20, 11:40 am, sushanth <sushant...@gmail.com> wrote:
> db=DAL('mysql://root:test1234...@localhost/new')
>
> db.define_table('dogs',
>        Field('id'),
>        Field('teamname'),primarykey=['teamname'],migrate=True
>      )
>
> db.define_table('users',
>     Field('name'),
>     Field('team',db.dogs)
>     )
>
> db.users.name.requires = IS_NOT_EMPTY()
> db.users.team.requires = IS_IN_DB(db, 'dogs.teamname', '%(dogs.teamname)')
>
> sql.log
>
> timestamp: 2010-12-20T22:39:05.866199
> CREATE TABLE dogs(
>     teamname VARCHAR(100) NOT NULL,
>     PRIMARY KEY(teamname))  ENGINE=InnoDB CHARACTER SET utf8;
> success!
> timestamp: 2010-12-20T22:39:05.968109
> CREATE TABLE users(
>     id INT AUTO_INCREMENT NOT NULL,
>     name VARCHAR(100),
>     team VARCHAR(100), INDEX team__idx (team), FOREIGN KEY (team) REFERENCES
> dogs(teamname),
>     PRIMARY KEY(id)
> ) ENGINE=InnoDB CHARACTER SET utf8;
> success!
>
> def index():
>     form=SQLFORM(db.users)
>     if form.accepts(request,session):
>             response.flash='new record inserted'
>     records=SQLTABLE(db().select(db.users.ALL))
>
>     return dict(form=form,records=records)
>
> I am able to create fk now with string,but if i insert any values into dogs
> table and refersh the page it throws error
>
> error :
>
> Traceback (most recent call last):
>   File "/home/sushanth/Desktop/web2py/gluon/restricted.py", line 188, in 
> restricted
>     exec ccode in environment
>   File 
> "/home/sushanth/Desktop/web2py/applications/welcome/controllers/default.py" 
> <http://127.0.0.1:8000/admin/default/edit/welcome/controllers/default.py>, 
> line 64, in <module>
>   File "/home/sushanth/Desktop/web2py/gluon/globals.py", line 95, in <lambda>
>     self._caller = lambda f: f()
>   File 
> "/home/sushanth/Desktop/web2py/applications/welcome/controllers/default.py" 
> <http://127.0.0.1:8000/admin/default/edit/welcome/controllers/default.py>, 
> line 12, in index
>     form=SQLFORM(db.users)
>   File "/home/sushanth/Desktop/web2py/gluon/sqlhtml.py", line 792, in __init__
>     inp = self.widgets.options.widget(field, default)
>   File "/home/sushanth/Desktop/web2py/gluon/sqlhtml.py", line 205, in widget
>     options = requires[0].options()
>   File "/home/sushanth/Desktop/web2py/gluon/validators.py", line 424, in 
> options
>     self.build_set()
>   File "/home/sushanth/Desktop/web2py/gluon/validators.py", line 419, in 
> build_set
>     self.labels = [self.label % dict(r) for r in records]
> KeyError: 'dogs.teamname'
>
> I think there is an issue with new dal.py with pymsql.
>
> can you please help me on this.
>
> Thanks
> sushanth

Reply via email to