In the 'aphorizm' table definition, you refer to db.author, but at that point, db.author doesn't yet exist. You have two options -- either reverse the order of the table definitions, or use the alternate syntax for defining a reference field: Field('author_id', 'reference author').
Anthony On Monday, December 12, 2011 9:43:12 PM UTC-5, Stanislaw Smetanin wrote: > > Hi community. I'm new to the web2py, but have a passion to learn it. > I'm a little stuck when start to define my models, I use MySQL engine, and > have following models: > > db = DAL('mysql://login:password@localhost/mydb') >> #db = DAL('sqlite://sqlite.sqlite') >> db.define_table('aphorizm', >> Field('body', 'text'), >> Field('author_id', db.author), >> Field('created_at'), >> Field('tags'), >> Field('like_count'), >> Field('slug'), >> Field('view_count')) >> db.define_table('author', >> Field('name'), >> Field('slug'), >> Field('created_at'), >> Field('user_id')) > > > but after successful saving I try the controller and have following > ticket's details: > > Traceback (most recent call last): > File "/var/www/web2py.catchword.mobi/gluon/restricted.py", line 194, in > restricted > exec ccode in environment > File "/var/www/web2py.catchword.mobi/applications/catchword/models/db.py" > <http://serv1.smetanin-online.name:8081/admin/default/edit/catchword/models/db.py>, > line 8, in <module> > Field('author_id', db.author), > File "/var/www/web2py.catchword.mobi/gluon/dal.py", line 4511, in > __getattr__ > return self[key] > File "/var/www/web2py.catchword.mobi/gluon/dal.py", line 4505, in > __getitem__ > return dict.__getitem__(self, str(key)) > KeyError: 'author' > > so i can't figure out what's the problem in the relation between > 'aphorizm' and 'author' models... I've defined the models according to the > official reference. > Please notice, when I change the engine from MySQL to SQLite all goes > fine, without any errors.. >