Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unique=True Not working. #587

Open
dipankar08 opened this issue Aug 15, 2013 · 1 comment
Open

unique=True Not working. #587

dipankar08 opened this issue Aug 15, 2013 · 1 comment

Comments

@dipankar08
Copy link

class User(Document):
#Required
username= StringField(required=True,max_length=10)
email = StringField(required=True,unique=True)
password= StringField(max_length=250,required=True)

u =User('xxx','[email protected]','123')
u.save()
u.save() <-- Not thronging any Exception.

@timjacobi
Copy link

Your code does not throw an error because you are saving the same object twice.
class User(Document):
username= StringField(required=True,max_length=10)
email = StringField(required=True,unique=True)
password= StringField(max_length=250,required=True)

u =User('xxx','[email protected]','123')
u.save()
u2 =User('xxx','[email protected]','123')
u2.save()

raise NotUniqueError(message % unicode(err))
mongoengine.errors.NotUniqueError: Tried to save duplicate unique keys (E11000 duplicate key error index: uniquetest.user.$email_1 dup key: { : "[email protected]" })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants