I remember something about adding a unique=True after "the first time" did not actually enforced at the db level the costraint. Can you please test if this happens also if you define a different table and you try to insert there ? I can't reproduce your situation with both trunk and 1.99.7 stable with postgres, mysql and sqlite (the second time I try to insert the same value in an unique=True column an error is thrown correctly)
On Saturday, August 18, 2012 9:47:24 PM UTC+2, Mike Girard wrote: > > I did do db.commit from the shell. Still no duplicate in the appadmin. > > On Saturday, August 18, 2012 3:12:39 PM UTC-4, Anthony wrote: >> >> In the shell, the transaction won't actually be committed until you do >> db.commit() (in your app code, you do not have to call db.commit() because >> it will be called automatically at the end of the request). Also, when you >> use .insert(), the validators don't run -- they only run when using SQLFORM >> or when you insert via .validate_and_insert(). >> >> Anthony >> >> 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? >>> >>> --