However. I just tried it and was told it can't be done. OperationalError: Cannot add a UNIQUE column
Error snapshot help <class 'pysqlite2.dbapi2.OperationalError'>(Cannot add a UNIQUE column) Bummer. BR, Jason Brower On Sun, Dec 30, 2012 at 8:16 AM, Bruno Rocha <[email protected]> wrote: can see two options. 1. Use form validation: def check_user(form): query = db.site.user == form.vars.user query &= db.site.location == form.vars.location if db(query).count(): form.errors.user = "already exists" def action(): form = SQLFORM(db.site) if form.process(onvalidation=check_user).accepted: # do whathever 2. Create a computed Uni-Key db.define_table('site', Field('location', 'string'), Field('user', db.auth_user, readable=False, writable=False), Field('typos', 'blob', readable=False, writable=False, default=None), Field('status', 'string', readable=False, writable=False, default='pending'), Field('last_scan', 'datetime', readable=False, writable=False, default=None), Field('unikey' , unique=True, notnull=True, compute=lambda row: "%(user)d_%(location)s" % row ) On Sun, Dec 30, 2012 at 4:06 AM, encompass <[email protected]> wrote: I have this in my model. db.define_table('site', Field('location', 'string'), Field('user', db.auth_user, readable=False, writable=False), Field('typos', 'blob', readable=False, writable=False, default=None), Field('status', 'string', readable=False, writable=False, default='pending'), Field('last_scan', 'datetime', readable=False, writable=False, default=None) ) db.site.status.requires = IS_IN_SET(['pending', 'working', 'done']) db.site.location.requires = IS_URL() I want it so that it validates that the combination of db.site.user and db.site.location are a unique value. How do I do that in web2py? I assume there is a way to do this in the model file and now in a controller with checks before insert. BR, Jason -- -- --

