Thanks for looking into it Massimo.. I will try using it with SQLite and GAE too!
On Tue, Sep 21, 2010 at 7:26 PM, mdipierro <[email protected]> wrote: > Do not know what to say. I do ot use MySQL because it has lots of > undocumented quirks. I quick search revealed other cases when the > problem may occur (look at the comments): > > http://www.danieltome.com/blog/2008/01/17/mysql-errno-150/ > > Anyway. This do not solve your problem. Try give the category > reference a default=0 and/or ondelete="NO ACTION" attribute. Does it > solve the problem? > > Massimo > > On Sep 21, 7:53 am, bally boy <[email protected]> wrote: > > When I do this, it works fine..but still I am not able to link the > > categories table to the product table, that is when the error pops up!:- > > > > db.define_table('product', > > Field('name',requires=IS_NOT_IN_DB(db,'product.name')), > > Field('image','upload'), > > Field('icon','upload'), > > > Field('price','double',requires=IS_FLOAT_IN_RANGE(0,1000)), > > Field('info','text',default=''), > > Field('category'), > > format='%(name)s ($%(price)s)') > > > > db.define_table('categories', > > > > > > Field('category',requires=IS_NOT_IN_DB(db,'categories.category')),format='%(category)s') > > > > db.define_table('order_item', > > Field('product',db.product), > > Field('buyer',db.auth_user), > > Field('quantity','integer'), > > Field('price','double'), > > Field('ordered_on','datetime',default=request.now)) > > > > I am able to link product table to the order_item table but am not able > to > > do the same with product and categories table!... I dont understand that! > > > > On Tue, Sep 21, 2010 at 6:07 PM, mdipierro <[email protected]> > wrote: > > > this is not a web2py error. OperationalError is a database error. I do > > > not think it is caused by this code. Soemthing is wrong with the db > > > config. > > > > > On Sep 21, 5:04 am, bally boy <[email protected]> wrote: > > > > Ok so this is a little tweaked code of the estore which Massimo > posted. > > > The > > > > original one works fine, but here I am just adding a table categories > :- > > > > > > db.define_table('categories', > > > > > > > Field('category',requires=IS_NOT_IN_DB(db,'categories.category')),format='%(category)s') > > > > > > db.define_table('product', > > > > Field('name',requires=IS_NOT_IN_DB(db,'product.name > ')), > > > > Field('image','upload'), > > > > Field('icon','upload'), > > > > > Field('price','double',requires=IS_FLOAT_IN_RANGE(0,1000)), > > > > Field('info','text',default=''), > > > > Field('category',db.categories), > > > > format='%(name)s ($%(price)s)') > > > > > > db.define_table('order_item', > > > > Field('product',db.product), > > > > Field('buyer',db.auth_user), > > > > Field('quantity','integer'), > > > > Field('price','double'), > > > > Field('ordered_on','datetime',default=request.now)) > > > > > > But I get this error here:- > > > > > > Traceback (most recent call last): > > > > File "/home/sathyavivek/web2pynew/gluon/restricted.py", line 186, > in > > > > restricted > > > > exec ccode in environment > > > > *File > > > **"/home/sathyavivek/web2pynew/applications/sathya/models/db_store.py"* > > > > <http://127.0.0.1:8000/admin/default/edit/sathya/models/db_store.py > >*, > > > > line 11, in <module> > > > > format='%(name)s ($%(price)s)'*) > > > > File "/home/sathyavivek/web2pynew/gluon/sql.py", line 1359, in > > > define_table > > > > t._create(migrate=migrate, fake_migrate=fake_migrate) > > > > File "/home/sathyavivek/web2pynew/gluon/sql.py", line 1845, in > _create > > > > fake_migrate=fake_migrate) > > > > File "/home/sathyavivek/web2pynew/gluon/sql.py", line 1914, in > _migrate > > > > self._db._execute(sub_query) > > > > File "/home/sathyavivek/web2pynew/gluon/sql.py", line 980, in > <lambda> > > > > self._execute = lambda *a, **b: self._cursor.execute(*a, **b) > > > > File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 166, > in > > > execute > > > > self.errorhandler(self, exc, value) > > > > File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line > 35, > > > > in defaulterrorhandler > > > > raise errorclass, errorvalue > > > > OperationalError: (1005, "Can't create table 'web2new.#sql-3e4_2bb' > > > > (errno: 150)") > > > > >

