Django 内存数据库模型创建失败
Django in-memory database model creation failure
我正在使用 MariaDB 内存引擎。我在my.cnf
中定义了max_heap_table_size
,重启了数据库服务。现在,我 运行 迁移并得到:
django.db.utils.ProgrammingError: Storage engine MEMORY doesn't support BLOB/TEXT columns
我的错误模型是:
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)
不过,max VARCHAR
是 65535.What 是问题吗?
由于文档状态 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.
由于 Django 模型中 CharField
的 max_length
指定了字符长度而不是字节长度,我认为这就是导致错误的原因。
创建 table MyISAM 或 InnoDB。两者都将快速缓存您的字符串,从而像 "in-memory".
一样做出响应
至于令人困惑的错误消息 -- 需要超过 64K 字节的 VARCHAR
被默默地变成了 MEDIUMTEXT
.
如果您的字符串可以分成多段,则可以有多行。 (第二列带有某种行号。)
我正在使用 MariaDB 内存引擎。我在my.cnf
中定义了max_heap_table_size
,重启了数据库服务。现在,我 运行 迁移并得到:
django.db.utils.ProgrammingError: Storage engine MEMORY doesn't support BLOB/TEXT columns
我的错误模型是:
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)
不过,max VARCHAR
是 65535.What 是问题吗?
由于文档状态 here,65.535
实际上是字节,如果使用 UTF-8
.
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.
由于 Django 模型中 CharField
的 max_length
指定了字符长度而不是字节长度,我认为这就是导致错误的原因。
创建 table MyISAM 或 InnoDB。两者都将快速缓存您的字符串,从而像 "in-memory".
一样做出响应至于令人困惑的错误消息 -- 需要超过 64K 字节的 VARCHAR
被默默地变成了 MEDIUMTEXT
.
如果您的字符串可以分成多段,则可以有多行。 (第二列带有某种行号。)