Python Django with MySQL:DatabaseError(1406,“第1行的列';名称';的数据太长”)
我有一个Django webapp,目前正在使用SQLite进行测试,但现在想要部署和使用MySQL,我遇到了这个错误 在使用Python Django with MySQL:DatabaseError(1406,“第1行的列';名称';的数据太长”),python,mysql,django,django-models,Python,Mysql,Django,Django Models,我有一个Django webapp,目前正在使用SQLite进行测试,但现在想要部署和使用MySQL,我遇到了这个错误 在使用python manage.py syncdb时,我纠正了这个错误: You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): no DatabaseError
python manage.py syncdb
时,我纠正了这个错误:
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): no
DatabaseError: (1406, "Data too long for column 'name' at row 4")
以及尝试使用此代码创建存储
对象(其中一个模型)时:
store_leicester = Store.objects.create(
name='Hugo Boss UK Store Leicester Square',
country='United Kingdom',
district='London',
catalog=catalog ...
)
错误:
DatabaseError at /populate/
(1406, "Data too long for column 'name' at row 1")
例如,商店模式是:
class Store(models.Model):
"""
Class for a Store.
"""
name = models.TextField(max_length=128)
country = models.TextField(max_length=64)
district = models.TextField(max_length=64)
catalog = models.OneToOneField('ShopCatalog', related_name='shop', null=True)
chain = models.ForeignKey('StoreChain', related_name="shops", null=True)
当然,这10-15个字符的文本并没有超过128个字符的限制,所以还有其他一些事情。首先,syncdb上也会出现错误
我正在使用我自己创建的两个使用模型的Django包,但我认为这不是问题所在
模式的默认排序规则是latin-1
,但我尝试切换到utf-8
,仍然出现完全相同的错误
谢谢当您
syncdb
时,Django还将模型的详细名称存储在其内部Django\u content\u type
表中。该表的限制为(从Django 1.2开始)100个字符。如果模型的详细名称超过100个字符,则会导致您遇到问题
检查您的应用程序是否有任何其他型号具有长名称/详细名称
,并尝试缩短它们。这应该可以解决问题。(Store
看起来一点也不长,但也许你没有提到另一种型号。)
顺便说一句,您在SQLite中没有看到这一点的原因是,如果我没记错的话,SQLite没有对char字段实施长度限制。您可能需要检查MySQL中的模式以验证列长度。我还建议使用django调试工具栏之类的工具来查看实际生成的查询。