You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django执行makemigrations报错,无法生成0001_initial.py迁移文件

Django makemigrations报错:TypeError: Field.init() got an unexpected keyword argument 'max_Length'

执行python manage.py makemigrations生成初始迁移文件时触发的错误,是由models.py中的两处拼写错误导致的:

错误原因

  • models.CharField(max_Length=200) 里的参数名拼写错误:应为**max_length**(Python对大小写敏感,Django字段参数采用小写命名规范)
  • models.Textfield(null=True, blank = True) 里的类名拼写错误:应为**TextField**(Django模型字段类名首字母需大写,完整类名为TextField)

修正后的models.py代码

from django.db import models


class Room(models.Model):
    #host =
    #topic =
    name = models.CharField(max_length=200)
    description = models.TextField(null=True, blank=True)
    #participants = 
    updated = models.DateTimeField(auto_now=True)
    created = models.DateTimeField(auto_now_add=True)


    def __str__(self):
        return str(self.name)

修正后重新执行python manage.py makemigrations即可生成0001_initial.py文件。

内容的提问来源于stack exchange,提问作者metkopetru

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 22:50:27