我可以将Django的auth_user.username字段更改为100个字符,不会破坏任何东西吗? [英] Can I change Django's auth_user.username field to be 100 chars long without breaking anything?

查看:167
本文介绍了我可以将Django的auth_user.username字段更改为100个字符,不会破坏任何东西吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某人将此问题标示为此问题的重复之前可以django的auth_user.username是varchar(75)吗?如何做到这一点?或其他这样的问题,请阅读这个问题。我链接的问题正好提出了这个问题,但不幸的是,答案并没有解决所提问题。

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, please read this question. The question I linked to asks this question precisely but unfortunately the answers don't address the question that was asked.

我可以将auth_user.username字段更改为100个字符执行以下操作:

Can I change the auth_user.username field to be 100 characters long by doing the following:


  1. 在DB中为用户名字段运行ALTER表

  2. 更改max_length这里: username = models.CharField(_('username'),max_length = 30,unique = True,help_text = _(必需30个字符或更少字母,数字和@ /。 + / - / _ characters))

  1. Run ALTER table in DB for the username field
  2. Change the max_length here: username = models.CharField(_('username'), max_length=30, unique=True, help_text=_("Required. 30 characters or fewer. Letters, numbers and @/./+/-/_ characters"))

如果我要做,这个?

当我将Django更新到更高版本时,这将会破坏不是问题。我也不是在编写其他的身份验证方法。我只想知道我是否会打破任何事情,如果我这样做。

That this will break when I update Django to a higher version is not a problem. I'm also not looking at writing other authentication methods.I just want to know if I would break anything if I were to do this.

推荐答案

您需要在几个地方使用monkey-patch max-length:model-field的描述,form-field的描述和max-length验证器。最大长度验证器附加到表单字段以及模型字段。

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 (测试与django 1.2和1.3)

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

更新:
好​​消息!由于django 1.5可以覆盖用户模型:自定义用户模型

这篇关于我可以将Django的auth_user.username字段更改为100个字符,不会破坏任何东西吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆