Just realised this is only an issue with legacy tables where there is a multi-field primary key. Normally you have autoincrement key so do not need to explicitly assign it.
Unfortunately with a multi-field primary key you cannot use update_or_insert anyway because for updates it calls update_record. On Wednesday, 12 December 2012 17:38:17 UTC, Massimo Di Pierro wrote: > > wd.update_or_insert(wd.category_id==category.webid, > name=category.name, > description=category.description) > > should be > > wd.update_or_insert(wd.category_id==category.webid, > category_id==category.webid, > name=category.name, > description=category.description) > > else category_id is always 0 (not sure why zero, should be none and fail > the not-null=True, perhaps you added this later and web2py did not pass it > along to the db). > > On Wednesday, 12 December 2012 10:15:57 UTC-6, simon wrote: >> >> I get a duplicate entry error on an update_or_insert. First record with >> category_id=1 is inserted fine. Second record with category_id=2 fails >> saying"Duplicate entry '0-1' for key 'PRIMARY'" >> >> Model: >> web.define_table('category_description', >> Field('category_id', 'integer', notnull=True, writable=False), >> Field('language_id', 'integer', notnull=True, writable=False, >> default=1), >> Field('name', 'text', length=255, notnull=True), >> Field('description', 'text', length=65535, notnull=True), >> primarykey=['category_id', 'language_id']) >> >> Controllert: >> wd=web.category_description >> wd.update_or_insert(wd.category_id==category.webid, >> name=category.name, >> description=category.description) >> > --