python - Django内存数据库模型创建失败

标签 python mysql django mariadb

我正在使用 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/

相关文章:

python - 使用 Pandas 对数据框进行列式映射和操作

python - 对 http-post 参数进行类型检查 Python;使用类型作为字典中的值

mysql - 使用 SQL 获取不同的行,但也获取整行

django - 在 ModelViewSet 中创建 Django 记录后获取其 ID

python - 任何 Python OLAP/MDX ORM 引擎?

python - 我有两个数据帧 DF1 和 DF2,在特定索引处追加满足从 DF2 到 DF1 条件的行的最佳方法是什么?

python - 更新来自不同进程的相同实例变量

java - 使用多线程更新数据库时如何避免 "lock timeout"?

mysql - 缓冲区长度小于 mysql percona 集群中的预期有效负载长度

python - 安全地从目录中的 GET 请求获取文件