0

我正在尝试将 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.

问题是什么?

4

1 回答 1

0

您正在使用“CsvDbModel”并且不应再定义字段,您的类应如下所示:

class MyCsvModel(CsvDbModel):

  class Meta:
    dbModel = Matchups
    delimiter = ","

否则,您应该改用“CsvModel”:

class MyCsvModel(CsvModel):
  name = CharField()
  vs_Ashe = CharField()

  class Meta:
    dbModel = Matchups
    delimiter = ","
于 2015-11-05T05:19:25.140 回答