In your model definition if you use : unique=True
For each field, It should build your db correctly... But maybe you want both field together to be unique... I don't remember how, but I think there is a way to tell web2py about multiple column constraint. I customize validator for doing this... I can show a bit the code if you want. Richard On Fri, Apr 13, 2012 at 10:34 AM, Johann Spies <johann.sp...@gmail.com>wrote: > On Friday, 13 April 2012 15:26:48 UTC+2, Massimo Di Pierro wrote: >> >> This has nothing to do with it. >> >> Anyway, recent version of web2py have automatic reconnect, if that is >> what you are asking. >> >> > Here is an example of what I wanted to do and which did not work in the > past but I see it is now working. To me that is important progress: > > db.define_table('toets', > > Field('f1'), > > Field('f2')) > > > Then in Postgresql: > > ALTER TABLE toets > > ADD CONSTRAINT geen_duplikaat UNIQUE(f1 , f2 ); > > def dup(): > > f1 = 'aaaa' > > f2 = 'bbbb' > > > > try: > > db.toets[0] = dict(f1 = f1, f2 = f2) > > except: > > print 'This combination is already in table "toets"' > > > > db.commit() > > return locals() > > > > In [6]: dup() > > dup() > > Out[6]: {'f1': 'aaaa', 'f2': 'bbbb'} > > > > In [7]: dup() > > dup() > > This combination is already in table "toets" > > Out[7]: {'f1': 'aaaa', 'f2': 'bbbb'} > > > Previously the connection the connection would break and a ticket issued > at this point. > > This enables me to make more use of database rules and constraints without > having web2py do do all the work. > > Regards > Johann >