django python manage.py migrate 后报错字段长度超了 django.db.utils.OperationalError: (1118 'Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535.

发布时间 2023-07-11 20:36:09作者: zhangmingda

 

现象:

在models.py 将CharField字段的maxlength=修改后,执行ython manage.py migrate  报错django.db.utils.OperationalError: (1118 'Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs')

我的触发操作 :

models.CharField(max_length=5120 改为  models.CharField(max_length=8192  然后就开始报错,再改回去5120仍然报错 ,无法恢复。

storage overhead, check the manual. You have to change some columns to TEXT or BLOBs')

django.db.utils.OperationalError: (1118, 'Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes
storage overhead, check the manual. You have to change some columns to TEXT or BLOBs')

报错

django.db.utils.OperationalError: (1118, 'Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes
storage overhead, check the manual. You have to change some columns to TEXT or BLOBs')

 

 解决方案:

找到最近改的CharField 字段,maxlength 长度超过CharField 允许值“”的修正后,将之前makemigrations生成的临时缓存文件删除,再更改字段即可。

步骤一、修改正models.py CharField字段

 

步骤二、删除之前CharField不支持的maxlength时, python manage.py makemigrations 生成的 项目名/migrations/xxxxx.py 缓存文件

 步骤三、 再次重新python manage.py makemigrations 生成字段变动文件python manage.py migrate 向数据库提交成功!!!

 

 发现:我的models.CharField(max_length 最多支持7159  ,7160就会提交失败了,这个值哪来的呢? 

看了这个链接也没有搞明白,朋友圈里大佬指教指教吧.....

https://blog.csdn.net/yinjinshui/article/details/102496340

我的数据库

mysql>  show create database monitor_test;
+--------------+--------------------------------------------------------------------------+
| Database     | Create Database                                                          |
+--------------+--------------------------------------------------------------------------+
| monitor_test | CREATE DATABASE `monitor_test` /*!40100 DEFAULT CHARACTER SET utf8mb4 */ |
+--------------+--------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql>