python - scrapy with django : how to use foreign key -
i want utilize scrapy django,but don't know how deal django foreignkey database postgresql
please guide me. give thanks you.
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() homecoming item if isinstance(item, shop_apple_imgitem): shopping = item.save(commit=false) shopping.save() homecoming item
spider this:
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
when run scrapy ,the error :
django.db.utils.integrityerror: null value in column "article_id" violates not-null constraint detail: failing row contains (1, null, http://test...).
have checked if have null value somewhere? seek setting default null test.
alter table article set default null
postgresql alter table
then run 1 time again see if same error.
python django scrapy
No comments:
Post a Comment