Greetings!
I seem to be having a problem using DAL with legacy databases, namely those
without an existing AUTO_INCREMENT field:
db.define_table('manufactured_by',
Field('product', 'string'),
Field('brand', 'string'),
primarykey=['product', 'brand'])
With a similar setup the update() function works well:
db.manufactured_by.insert(product="Perfume", brand="Chanel")
rset = db(db.manufactured_by.product=="Perfume")
rset.update(brand="Dior")
Whereas the update_record() function throws an error -- KeyError:
'update_record':
row = rset.select().first()
row.update_record(brand="Fendi")
Same for update_or_insert() which relies on calling update_record(). Tried
with SQLite and MySQL backends. Is there any way to make those work?
Many thanks!
Dmitry
from gluon.dal import DAL, Field
db = DAL('sqlite://sqlite.db')
db.define_table('manufactured_by',
Field('product','string'),
Field('brand', 'string'),
primarykey=['product', 'brand'])
db.manufactured_by.insert(product="Perfume", brand="Chanel")
rset = db(db.manufactured_by.product=="Perfume")
row = rset.select().first()
print "product =", row.product, ", brand =", row.brand
# This one works fine
rset.update(brand="Dior")
row = rset.select().first()
print "product =", row.product, ", brand =", row.brand
# This throws an error -- KeyError: 'update_record'.
row.update_record(brand="Fendi")
print "product =", row.product, ", brand =", row.brand
# Same error for update_or_insert(), which calls update_record()