Python 3.x Django会自动更改驼峰大小写
我在Django中使用models.IntegerChoices作为枚举,但它以一种改变的方式保存在DB中Python 3.x Django会自动更改驼峰大小写,python-3.x,django,database-migration,Python 3.x,Django,Database Migration,我在Django中使用models.IntegerChoices作为枚举,但它以一种改变的方式保存在DB中 class FruitsEnum(models.IntegerChoices): Apple = 1 RedApple = 2 GreenApple = 3 LongBanana = 4 DragonFruit = 5 但它是这样保存在数据库中的:[('0','Apple'),('1','Redapple'),('2','Greenapple')…
class FruitsEnum(models.IntegerChoices):
Apple = 1
RedApple = 2
GreenApple = 3
LongBanana = 4
DragonFruit = 5
但它是这样保存在数据库中的:[('0','Apple'),('1','Redapple'),('2','Greenapple')…]
正如你所见,“苹果”这个词在两个单词组合中不是大写的。我怎样才能做到这一点:
[('0','Apple'),('1','RedApple),('2','GreenApple)…]只传递由整数和相关名称组成的元组,而不是传递整数。比如:
水果类(模型、整数选择):
苹果=1,‘苹果’
红苹果=2,‘红苹果’
绿苹果=3,“绿苹果”
长香蕉=4,‘长香蕉’
龙果=5,‘龙果’
或者,在您的模型中,在使用此选项的IntegerField
中,您可以用元组替换foultsenum.choices
:
[(1,'Apple'),(2,'RedApple'),(3,'GreenApple'),(4,'LongBanana'),(5,'DragonFruit')]
注意:您在这里观察到的任何差异纯粹是表面的,不存在于django之外(即数据库内)。您可以直接打开数据库,看到表中只存储整数