How to make email field unique in model User from contrib.auth in Django

后端 未结 19 2138
夕颜
夕颜 2020-11-27 11:47

I need to patch the standard User model of contrib.auth by ensuring the email field entry is unique:

User._meta.fields[4].unique = True
<         


        
19条回答
  •  孤街浪徒
    2020-11-27 12:09

    Simply use below code in models.py of any app

    from django.contrib.auth.models import User
    User._meta.get_field('email')._unique = True
    

提交回复
热议问题