Django的auth用户截取电子邮件领域 [英] django auth User truncating email field
问题描述
我与django.contrib.auth用户模型,其中电子邮件MAX_LENGTH是75个问题。
I have an issue with the django.contrib.auth User model where the email max_length is 75.
我收到了来自Facebook的API超过75个字符的电子邮件地址,我需要(真的想)在用户的连续性它们存储是从Facebook的用户连接和其他人之间。
I am receiving email addresses that are longer than 75 characters from the facebook api, and I need to (would really like to) store them in the user for continuity among users that are from facebook connect and others.
我能够解决的问题,数据截断列电子邮件在第1行
通过手动去编辑我们的MySQL数据库中的字段,但<强>有没有更好的办法来pferably解决这个问题? $ p $一个不涉及我手动编辑数据库我每次重置为架构更改时间?
I am able to solve the problem of "Data truncated for column 'email' at row 1
" by manually going editing the field in our mySql database, but is there a better way to solve this? preferably one that does not involve me manually editing the database every time I reset it for a schema change?
我行与编辑数据库,只要我可以把它添加到复位脚本或initial_data.json文件。
I am ok with editing the database as long as I can add it to the reset script, or the initial_data.json file.
推荐答案
EmailField 75个字符的长度是在Django硬codeD。你可以解决这个问题这样的:
EmailField 75 chars length is hardcoded in django. You can fix this like that:
from django.db.models.fields import EmailField
def email_field_init(self, *args, **kwargs):
kwargs['max_length'] = kwargs.get('max_length', 200)
CharField.__init__(self, *args, **kwargs)
EmailField.__init__ = email_field_init
但是这将改变所有EmailField领域的长度,所以你也可以尝试:
but this will change ALL EmailField fields lengths, so you could also try:
from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
from django.db import models
User.email = models.EmailField(_('e-mail address'), blank=True, max_length=200)
这将会是最好的两种方式把这个code中的任何模块的初始化之前django.contrib.auth在INSTALLED_APPS
both ways it'd be best to put this code in init of any module BEFORE django.contrib.auth in your INSTALLED_APPS
这篇关于Django的auth用户截取电子邮件领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!