Django 对模型的字段名有一些限制:

  1. 一个字段的名称不能是 Python 保留字,因为这会导致 Python 语法错误。比如:

    class Example(models.Model):
        pass = models.IntegerField() # 'pass' is a reserved word!
    
  2. 一个字段名称不能包含连续的多个下划线,原因在于 Django 查询语法的工作方式。比如:

    class Example(models.Model):
        foo__bar = models.IntegerField() # 'foo__bar' has two underscores!
    
  3. 字段名不能以下划线结尾,原因同上。