web2py can't set a multi-column constraint at the database level, so you'll 
have to do that directly in the database (once you do that, attempting an 
insert that violates the constraint will cause a database exception to be 
thrown).

If you want form validation with friendly error messages (rather than a 
database exception), you can do:

db.mytable.f2.requires = IS_NOT_IN_DB(db(db.mytable.f1 == request.vars.f1), 
'mytable.f2',
                                      error_message='This combination of f1 
and f2 already taken.')

That says that for the set of records where f1 matches the current value 
submitted for f1 (i.e., request.vars.f1), the current value being inserted 
for f2 must be unique (which is equivalent to saying the pair of values 
must be unique). Alternatively, you could define the validator on f1, with 
appropriate changes (or define it on both, though that would be redundant).

Anthony

On Friday, January 31, 2014 4:36:31 AM UTC-5, software.ted wrote:
>
> I have a table:
>
> db.define_table('mytable', Field('f1'), Field('F2'))
>
> I want to make F1 and F2 together with with the 'invisible id' as a 
> compound primary key. I want the new records to have unique f1 and f2
>
> Kind regards,
>

-- 
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/groups/opt_out.

Reply via email to