我想用scrapy Django的,但我不知道該如何處理Django的外鍵
我的數據庫PostgreSQL的是scrapy和Django:如何使用外鍵
請指引我。謝謝。
models.py:
class ShoppingApple(models.Model):
link = models.URLField(max_length=255)
title = models.CharField(max_length=100)
class ImageApple(models.Model):
article = models.ForeignKey(ShoppingApple)
image =models.CharField(max_length=255)
pipelines.py:
class ShopPipeline(object):
if isinstance(item, Shop_appleItem):
shopping = item.save(commit=False)
shopping.save()
return item
if isinstance(item, Shop_apple_imgItem):
shopping = item.save(commit=False)
shopping.save()
return item
蜘蛛這樣的:
def parse(self,response):
item = Shopping_appleItem()
product = Shopping_apple_imgItem()
sel = Selector(response)
item['link'] = sel.css(" ").extract()
item['title'] = sel.css(" ").extract()
product['image'] = sel.css(" ").extract()
yield item
yield product
當我跑我的scrapy,錯誤的是:
django.db.utils.IntegrityError: null value in column "article_id" violates not-null constraint
DETAIL: Failing row contains (1, null, http://test...).
我發現這也許是因爲我沒有保存'''''''',但我stiil不知道該怎麼辦 – user2492364 2014-10-06 08:30:44