Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
字段';id';应为一个数字,但得到';ANPKUR0724';在Django中导入数据时_Django_Django Models_Error Handling_Django Admin_Django Import Export - Fatal编程技术网

字段';id';应为一个数字,但得到';ANPKUR0724';在Django中导入数据时

字段';id';应为一个数字,但得到';ANPKUR0724';在Django中导入数据时,django,django-models,error-handling,django-admin,django-import-export,Django,Django Models,Error Handling,Django Admin,Django Import Export,我有两个模型,通过外键关联,当我上传有外键的模型时,自动创建的id值取外键字段的值。可能的原因是什么 class Station(models.Model): BS_ID = models.TextField(max_length=20,unique=True) BS_Name = models.CharField(max_length=20) City = models.CharField(max_length=20,null=Tr

我有两个模型,通过外键关联,当我上传有外键的模型时,自动创建的id值取外键字段的值。可能的原因是什么

 class Station(models.Model):
          BS_ID = models.TextField(max_length=20,unique=True)
          BS_Name = models.CharField(max_length=20)
          City = models.CharField(max_length=20,null=True)
          State = models.CharField(max_length=20,null=True)
          City_Tier = models.CharField(max_length=10,null=True)
          Lat = models.DecimalField(max_digits=10,decimal_places=5,null=True,blank=True)
          Long = models.DecimalField(max_digits=10,decimal_places=5,null=True,blank=True)
    
    class CustomerLVPN(models.Model):
      Customer_Name = models.CharField(max_length=200)
      Order_Type = models.CharField(max_length=200,null=True)
      Feasibility_ID = models.IntegerField(null=True)
      Circuit_ID = models.CharField(max_length=250,null=True,blank=True)
      Req_BW = models.DecimalField(max_digits=6,decimal_places=3,null=True,blank=True)
      City = models.CharField(max_length=200,null=True)
      State = models.CharField(max_length=200,null=True)
      Region =models.CharField(max_length=200,null=True)
      L2_Lat = models.DecimalField(max_digits=6,decimal_places=3,null=True,blank=True)
      L2_Long = models.DecimalField(max_digits=6,decimal_places=3,null=True,blank=True)
      BS_ID = models.ForeignKey(Station,to_field='BS_ID',related_name='ConfirmedCustomer',on_delete=models.SET_NULL,null=True)
因此,当我上传CustomerVPN模型的数据时,我得到以下错误- “B_ID 字段“id”需要一个数字,但得到了“ANPKUR0724”。”

以下是资源代码:

class StationResource(resources.ModelResource):
    class Meta:
        model=Station
        exclude = ['id']
        use_bulk=True
        batch_size = 500

class StationAdmin(ImportExportModelAdmin):
    resource_class=StationResource


class LVPNResource(resources.ModelResource):

    class Meta:
        model = CustomerLVPN
        use_bulk = True
        batch_size = 500

class LVPNAdmin(ImportExportModelAdmin):
    resource_class = LVPNResource

对于您的
LVPNResource
您需要将a与您的
bs_id
字段关联:

bs_id=fields.Field(
列\u name='BS\u ID',
attribute='BS_ID',
widget=ForeignKeyWidget(站点'BS_ID'))

您可以发布您的资源声明,并在上面添加资源声明的示例导入行(已编辑)。对于导入im,您可以使用excel文件,其中每个字段都有值。