运行scrapy时显示错误,例如ValueError:无法分配“'1'”:“ Mymodel2.mycatogry_id”必须是“ Mymodel”实例

时间:2019-12-02 13:17:27

标签: django-models web-scraping scrapy web-crawler mysql-python

运行scrapy爬网myapp时,它将显示错误,例如ValueError:无法分配“'1'”:“ Mymodel2.mycatogry_id”必须是“ Mymodel”实例。能解决这个问题吗?

Models.py

class Mymodel(models.Model):
  mycatogry = models.CharField(max_length=50)


class Mymodel1(models.Model):
 news_catogry = models.ForeignKey(Mymodel)
 mysubcatogry = models.CharField(max_length=500)




class Mymodel2(models.Model):
  provider_id = models.CharField(max_length=50)
  title = models.CharField(max_length=500)
  details = models.CharField(max_length=500)
  image = models.CharField(max_length=800)
  page_url = models.CharField(max_length=500)
  page = models.CharField(max_length=500)
  des = models.CharField(max_length=13000)
  mycatogry_id = models.ForeignKey(Mymodel)
  mysubcatogry_id = models.ForeignKey(Mymodel1)

items.py

from scrapy_djangoitem import DjangoItem

from duklrapp.models import Mymodel2


class MycrawlItem(DjangoItem):

  django_model = Mymodel2

pipeline.py

class NewscrawlPipeline(object):
def process_item(self, item, spider):
    item.save()
    return item

0 个答案:

没有答案