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

后端 未结 19 2032
夕颜
夕颜 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:04

    In settings module:

    # Fix: username length is too small,email must be unique
    from django.contrib.auth.models import User, models
    User._meta.local_fields[1].__dict__['max_length'] = 75
    User._meta.local_fields[4].__dict__['_unique'] = True
    

提交回复
热议问题