Ok, so I brought up a new shell and the duplicate record was gone.

So can I confirm that field constraints get enforced with db.insert and 
therefore, any DAL method I use for inserting records is sound in this 
respect? I don't want to do a huge data dump and then have to do a lot of 
post-processing for duplicate records.

Thanks. 

On Saturday, August 18, 2012 2:50:18 PM UTC-4, Mike Girard wrote:
>
> In preparation for doing a bulk insert into my app's tables I have been 
> doing some testing from the web2py shell.
>
> I issued the following command:
>
> >>db.person.insert(name = 'Dustin Hoffman')
>
> person.name has a unique=true setting as well as an IS_NOT_IN_DB form 
> constraint. Dustin Hoffman is already in the database. 
>
> The response for running this command was an id number (118)  suggesting 
> the record had been added. However, when I looked at the person records via 
> /myapplication/appadmin, it wasn't there and the id of the last record was 
> 117. This is fine, suggesting that the uniqueness constraint had been 
> applied.
>
> However, when I went back to the shell and issued this command -
>
> >> db.person(118) 
>
> - It returned a row.  Also
>
> >> db.person(name='Dustin Hoffman').count
> >> 2
>
> So it seems as if the duplicate record is in the db, though it doesn't 
> show up in the browser.
>
> Two questions, then:
>
> 1. Why is the duplicate record not showing up in /myapplication/appadmin
> 2. If I want a script where duplicates are just rejected without special 
> handling, should I just use insert_and_validate? What if I am doing a bulk 
> insert or a csv import? 
>
>

-- 



Reply via email to