Another glitch with legacy keyed tables is that text fields of type 'reference table.field' aren't encoded for SQL correctly (at least, not for SQLite). They end up in the SQL as u'key', which creates a syntax error.
On Friday, October 1, 2010 7:19:47 AM UTC-4, Ivan Matveev wrote: > > Hello All, > I'm trying to make a web2py interface to a legacy db(mysql). > The db is defined like this: > > CREATE TABLE `car_models` ( > `model_id` int(10) unsigned NOT NULL auto_increment, > `model_name` text NOT NULL, > PRIMARY KEY (`model_id`) > ) > > CREATE TABLE `cars` ( > `car_id` int(10) unsigned NOT NULL auto_increment, > `model_id` int(10) unsigned NOT NULL, > PRIMARY KEY (`car_id`) > ) > > a model: > > db.define_table('car_models', > Field('model_id','integer'), > Field('model_name','string'), > primarykey=['model_id'], > migrate=False > ) > > db.define_table('cars', > Field('car_id','integer'), > Field('model_id','integer'), > Field('note','text'), > primarykey=['car_id'], > migrate=False > ) > > works fine in appadmin. Shows tables, inserts/edits rows. > But if I'm trying to define a reference > > db.define_table('cars', > Field('car_id','integer'), > Field('model_id', db.car_models.model_id), > Field('note','text'), > primarykey=['car_id'], > migrate=False > ) > > I get this error: > > Error traceback > > Traceback (most recent call last): > File "/home/ivm/prg/web2py/gluon/restricted.py", line 186, in > restricted > exec ccode in environment > File "/home/ivm/prg/web2py/applications/monicar_db_test/controllers/ > appadmin.py", line 410, in ? > File "/home/ivm/prg/web2py/gluon/globals.py", line 96, in <lambda> > self._caller = lambda f: f() > File "/home/ivm/prg/web2py/applications/monicar_db_test/controllers/ > appadmin.py", line 124, in insert > form = SQLFORM(db[table], ignore_rw=ignore_rw) > File "/home/ivm/prg/web2py/gluon/sqlhtml.py", line 668, in __init__ > if field.type == 'id': > File "/home/ivm/prg/web2py/gluon/sql.py", line 2551, in __eq__ > return Query(self, '=', value) > File "/home/ivm/prg/web2py/gluon/sql.py", line 2993, in __init__ > right = sql_represent(right, left.type, left._db._dbname, > left._db._db_codec) > File "/home/ivm/prg/web2py/gluon/sql.py", line 555, in sql_represent > return str(int(obj)) > ValueError: invalid literal for int(): id > > Looks like DAL wants me to refere to a field of type 'id' > > but if I change 'model_id' field type to id > > db.define_table('car_models', > Field('model_id','id'), > Field('model_name','string'), > primarykey=['model_id'], > migrate=False > ) > > appadmin shows 'car_models' but doesn't let me edit rows > and shows empty 'cars' table(its not empty ) > > web2py 1.83.2 > python2.4 > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.