Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8960607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:41:49+00:00 2026-06-15T15:41:49+00:00

I defined a table as follows: db.define_table(‘special_users’, Field(‘sp_user’, db.auth_user, required=True, notnull=True, label=’Special User’, represent=lambda

  • 0

I defined a table as follows:

db.define_table('special_users',
    Field('sp_user', db.auth_user, required=True, notnull=True, label='Special User', represent=lambda lead,row: lead.first_name + ' ' + lead.last_name, unique=True),
    format=lambda row: (row.lead.first_name + ' ' + row.lead.last_name) or 'N/A')

And I specified the requires constraint as follows

db.special_users.lead.requires = IS_IN_DB(db, db.auth_user, '%(first_name)s %(last_name)s', zero=None)

Now, when I generate a form for the table using SQLFORM(db.special_users) it allows me to add a user as many times as I want, which is a violation of unique=True constraint. How can I get this rectified?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:41:51+00:00Added an answer on June 15, 2026 at 3:41 pm

    For some reason, I think maybe notnull and unique constraints don’t get applied to reference fields. In any case, if inserts are generally made via forms, you are better off using an IS_NOT_IN_DB() validator on the field, as that will enable proper error handling and display when processing the form. Relying only on unique=True would result in an exception upon a duplicate insert attempt, which would generate a non-specific 500 server error for the end user.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table defined as follows: CREATE TABLE [dbo].[T]( [FileID] [bigint] NOT NULL,
I have a nvarchar(50) column in a SQL Server 2000 table defined as follows:
I have an entity defined as follows @Entity(name = Report) @Table(name = REPORTS) @org.hibernate.annotations.Entity(dynamicInsert
I have a table in a postgresql-9.1.x database which is defined as follows: #
I have a table defined as follows in HTML: <table border=0 cellpadding=0 cellspacing=0 style=width:100%;>
In my database, assume we have a table defined as follows: CREATE TABLE [Chemical](
Say, I have a table in the DB defined as follows Table: Foo PkId
I have a table defined as follows: CREATE TABLE `mydb`.`users` ( `userID` int(10) unsigned
The table is defined as follows: CREATE TABLE Session ( id bigint(20) UNSIGNED NOT
I have a parent/child/grandchild type table relationship defined as follows: tableA: parentID description tableB:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.