0

嗨,我有一个 PHP 项目,我想用 Django 开发相同的项目,出于多种原因,我决定创建一个新数据库,所以现在我必须将所有数据从旧数据库导出到新数据库,为此我使用我为 Django 开发的模型,它一直有效,直到我遇到这个错误:

_mysql_exceptions.Warning: Data truncated for column 'bloomberg' at row 1

这是我正在试验这个问题的表的模型:

class Contact(models.Model):
company_id = models.ForeignKey(Company)
address = models.CharField(max_length=150)
first_name= models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
role = models.CharField(max_length=20)
sector = models.CharField(max_length=45)
work_phone = models.CharField(max_length=30)
contact_source = models.CharField(max_length=30)
alt_work_phone = models.CharField(max_length=30)
mobile_phone = models.CharField(max_length=30)
work_fax = models.CharField(max_length=30)
bloomberg = models.CharField(max_length=60)
work_email = models.CharField(max_length=60)
research_email = models.CharField(max_length=60)
product_focus = models.CharField(max_length=2)
preferred_email = models.CharField(max_length=60)
job_title = models.CharField(max_length=80)
created_by = models.CharField(max_length=25)
legal_entity_name = models.CharField(max_length=100)
status= models.ForeignKey(Status)
title = models.CharField(max_length=5)
zipcode = models.CharField(max_length=10)
country = models.CharField(max_length=15)
city= models.CharField(max_length=20)
created_date=models.DateTimeField('creation date ')
updated_date=models.DateTimeField('update date ')
updated_by = models.CharField(max_length=20)
parent = models.CharField(max_length=45)
address_line_2 = models.CharField(max_length=100)
new = models.BooleanField()
hided = models.BooleanField()
employee = models.BooleanField()

def __unicode__(self):
    s = u" Contact "
    return s + self.first_name + " " + self.last_name

两个数据库中的字段长度相同,所以我不明白这个错误,谷歌搜索后我注意到通常这个问题是通过修复列的尺寸来解决的,但这不是我的情况。有人可以告诉我如何解决吗?

4

1 回答 1

0

看起来 60 个字符对于您的“bloombergs”来说是不够的。尝试将其设置得更高,例如:

bloomberg = models.CharField(max_length=255)

请注意,如果您已经同步了模型,您还必须在数据库级别执行此操作。希望这可以帮助。

于 2012-11-22T16:04:52.773 回答