Django自定义字段方法不会在mysql中创建枚举字段

时间:2018-05-25 05:01:16

标签: django django-models

我的代码如下所示:

let employeeNames = ["Donkey", "Horse", "Zebra","Okapi"]
    for i in 0..<employeeNames.count
    {
        let employeeEntry = NSEntityDescription.insertNewObjectForEntityForName("ZooAnimals", inManagedObjectContext: managedObject)

        employeeEntry.setValue(employeeNames[i], forKey: "employeename")
        employees.setValue(index, forKey: "animal")

        do {
            try managedObject.save()
        } catch {
            print("problem saving")
        }
    }

通过这段代码,我试图在mysql中创建class CharMaxlength25Field(models.Field): def db_type(self, connection): return 'enum(android,ios)' class search(models.Model): class Meta: db_table = 'search' city_name = CharMaxlength25Field() 字段。现在,当我尝试使用enum步骤运行此架构时,出现以下错误:

python manage.py makemigrations

1 个答案:

答案 0 :(得分:1)

尝试添加引号:

class CharMaxlength25Field(models.Field):
    def db_type(self, connection):
        return 'enum("android","ios")'