我正在尝试将csv文件导入我的SQL数据库。这是我的模特:
class Matchups(models.Model):
name = models.CharField(max_length=140)
vs_Ashe = models.CharField(max_length=140)
def __unicode__(self):
return "%s" % (self.name)
class MyCsvModel(CsvDbModel):
name = CharField()
vs_Ashe = CharField()
class Meta:
dbModel = Matchups
delimiter = ","
尝试导入csv文件时:my_csv_list = MyCsvModel.import_data(data = open("/home/irmantas/ADC.csv"))
我收到此错误:
A Db model should not have any csv field defined.
有什么问题?
答案 0 :(得分:0)
你正在使用'CsvDbModel'并且不应再定义字段,你的类应该看起来:
class MyCsvModel(CsvDbModel):
class Meta:
dbModel = Matchups
delimiter = ","
否则你应该使用'CsvModel'代替:
class MyCsvModel(CsvModel):
name = CharField()
vs_Ashe = CharField()
class Meta:
dbModel = Matchups
delimiter = ","