I udnerstand. Usually this is not required because the primary key is 
autoincrement. However here I have a legacy table with migrate disabled and 
a primary key made up of two fields which are not autoincrement.

Would it not be more friendly to use the condition as the default value for 
the field? Having to assign the field explicitly is either redundant or in 
conflict with the condition. Also somewhat confusing to 
have update_or_insert which fails with duplicate key as one might expect it 
either updates or inserts.

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)
>>
>

-- 



Reply via email to