the composite pkey isn't in the model either: there was no way for us to 
identify that :P

On Thursday, March 26, 2015 at 8:28:37 PM UTC+1, Ian W. Scott wrote:
>
> Found the problem. There were two rows with the same combination of 'name' 
> and 'tag' values. That didn't violate any constraints on the table 
> definition, so normally there was no difficulty. But it violated the 
> "unique" constraint on the postgre index that indexed the 'name' and 'tag' 
> columns together.
>
> In case it helps anyone else, I stumbled across the bad data by dropping 
> the index from the table (directly using postgresql, not via the dal) and 
> then trying to re-create the index. Since I was using pgAdmin to do this, 
> it gave me an error message identifying the offending combination of values.
>
> Ian
>
> On Wednesday, March 25, 2015 at 6:12:18 PM UTC-4, Ian W. Scott wrote:
>>
>> In a test function I set up some testing data in a postgresql database by 
>> first deleting my test user's data and then inserting from a dictionary:
>>
>>         db(db.tag_records.name == user_login['id']).delete()
>>         db.commit()
>>         for tr in trecs:
>>
>>             db.tag_records.insert(**tr)
>>
>> When this hits the insert I consistently get the following error: 
>>
>>     ProgrammingError: ('ERROR', '23505', 'duplicate key value violates 
>> unique constraint "idx_name_tag"')
>>
>> I've reindexed the whole database but that doesn't seem to help. 
>> Strangely, it seems like this error comes up on the *second* run of the 
>> code. In other words, the first run through the test the rows are deleted 
>> and new rows inserted just fine. It's when the test function runs a second 
>> time (there are several sets of test data) that this error appears.
>>
>> I've never run into a problem like this before, and I'm not very good 
>> with the internals of postgresql yet. So any help is greatly appreciated. 
>>
>> The table definition looks like this:
>>
>> db.define_table('tag_records',
>>                 Field('name', db.auth_user, default=auth.user_id),
>>                 Field('tag', db.tags),
>>                 Field('times_right', 'double'),
>>                 Field('times_wrong', 'double'),
>>                 Field('tlast_wrong', 'datetime', default=dtnow),
>>                 Field('tlast_right', 'datetime', default=dtnow),
>>                 Field('in_path', db.paths),  # was path (reserved term)
>>                 Field('step', db.steps),
>>                 Field('secondary_right', 'list:string'),
>>                 Field('uuid', length=64, default=lambda:str(uuid.uuid4
>> ())),
>>                 Field('modified_on', 'datetime', default=request.now),
>>                 )
>> db.tag_records.name.requires = IS_IN_DB(db, 'auth_user.id',
>>                                     db.auth_user._format)
>> db.tag_records.tag.requires = IS_IN_DB(db, 'tags.id', db.tags._format)
>> db.tag_records.step.requires = IS_IN_DB(db, 'steps.id', db.steps._format)
>> db.tag_records.in_path.requires = IS_IN_DB(db, 'paths.id', db.paths.
>> _format)
>>
>>
>>
>>

-- 
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/d/optout.

Reply via email to