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

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

    Add somewhere this:

    User._meta.get_field_by_name('email')[0]._unique = True     
    

    and then execute SQL similar to this:

    ALTER TABLE auth_user ADD UNIQUE (email);
    

提交回复
热议问题