我正在使用 MariaDB MEMORY 引擎。我在my.cnf
中定义了max_heap_table_size
,重新启动了数据库服务。现在,我运行迁移并得到:
django.db.utils.ProgrammingError:存储引擎 MEMORY 不支持 BLOB/TEXT 列
我的错误模型是:
class Department(models.Model):
name = models.CharField(max_length=100)
tag = models.CharField(max_length=10)
dtype = models.PositiveSmallIntegerField()
info = models.CharField(max_length=64000)
但是,最大 VARCHAR
是 65535。问题是什么?
最佳答案
正如文档所述 here , 65.535
实际上是字节,如果使用 UTF-8
,则最多可容纳 21.844 个字符。
A variable-length string. M represents the maximum column length in characters. The range of M is 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used. For example, utf8 characters can require up to three bytes per character, so a VARCHAR column that uses the utf8 character set can be declared to be a maximum of 21,844 characters.
自 max_length
Django 模型中的 CharField
指定字符长度而不是字节长度,我认为这就是导致错误的原因。
关于python - Django内存数据库模型创建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30787677/