Can I change Django's auth_user.username field to be 100 chars long without breaking anything?

前端 未结 7 1493
眼角桃花
眼角桃花 2021-02-06 05:31

Before somebody marks this question as a duplicate of this question Can django\'s auth_user.username be varchar(75)? How could that be done? or other such questions on SO, pleas

相关标签:
7条回答
  • 2021-02-06 05:53

    for future needs this is the best and easiest way i found out:

    https://github.com/GoodCloud/django-longer-username

    0 讨论(0)
  • 2021-02-06 06:03

    If you change the database manually as well as the model accordingly then there should be no problem.

    You can also change back otherwise, and I would say make a backup just in case but I'm not sure its even necessary

    0 讨论(0)
  • 2021-02-06 06:04

    You need to monkey-patch max-length in several places: model-field's description, form-field's description and max-length validators. Max-length validators are attached to form-fields as well as model-fields.

    Here is a code snippet, which will patch everything:

    https://gist.github.com/1143957 (tested with django 1.2 and 1.3)

    Update: Good news! Since django 1.5 you can override user model: Customizing the User model

    0 讨论(0)
  • 2021-02-06 06:08

    Another solution is to change your authentication code. When a new user signs up, they enter an email, you save this in the email field so you have it, and if their email is >30 characters, you shorten it before putting it into the user field. Then, change your login authentication for new logins.

    0 讨论(0)
  • 2021-02-06 06:09

    There is no harm in doing that. Just change the length in the model and in the database :)

    0 讨论(0)
  • 2021-02-06 06:11

    Create a user profile model, add your very-long-username field there, and use it. of course this renders the genuine username field useless, but it is much better than hacking Django code, which will get you into trouble when you need to upgrade it.

    0 讨论(0)
提交回复
热议问题