Make ’email’ field to be unique in Django Model


To create a unique email field in your Django User model, so that only one user can be associated with an email address, add below to your model:


from django.contrib.auth.models import User


Class UserModel(UserCreationForm):
...
  email = forms.EmailField(required=True)
...
 

  User._meta.get_field_by_name('email').unique=True

Rate this Article
Sending
User Review
0 (0 votes)


About Matthias 33 Articles
I am a Software Engineer from Houston, TX who love to write codes that brings great ideas to live. In my professional life, I have created software for different industries including Oil & Gas, Finance, Service Provider, Cloud Computing and Embedded Systems. When not writting codes, i enjoy travelling, good music and photography. You can reach me at me@matthiasomisore.com.

Be the first to comment

Leave a Reply

Your email address will not be published.


*