我有一个Django的web应用程序,目前一直在用SQLite测试,但现在想部署和使用MySQL,这个错误。Django与MySQL:DatabaseError(1406,“数据太长,列'名称'第1行”)
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
对象(机型之一)与此代码时:
store_leicester = Store.objects.create(
name='Hugo Boss UK Store Leicester Square',
country='United Kingdom',
district='London',
catalog=catalog ...
)
错误:
我使用时python manage.py syncdb
收到此错误权
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
,但仍完全相同的错误。
谢谢
您可能想检查MySQL中的模式以验证列长度。我还建议使用像django-debug-toolbar这样的工具来查看实际正在生成的查询。 – 2013-04-30 22:37:29