I'm currently doing a web scraper app using selenium. It is supposed to 
scrape several reviews, but it won't proceed because of the error.  Any 
help would be greatly appreciated.

Error:
UNIQUE constraint failed: seleniumapp_comment.id

models.py:

class ReviewWebsite(models.Model):
    website_name = models.CharField(max_length=50)
    website_url = models.TextField()

    def __str__(self):
        return self.website_name + " " + self.website_url


class Comment(models.Model):
    website = models.ForeignKey(ReviewWebsite, on_delete=models.CASCADE)
    comment_title = models.TextField()
    comment_content = models.TextField()
    comment_score = models.CharField(max_length=7)
    comment_date = models.CharField(max_length=50)



snippet of the external python script:

def insert_to_db(website_name, title, content, score, review_date):

    if website_name == "agoda":
        site_id = 1
    elif website_name == "tripadvisor":
        site_id = 2
    else:
        site_id = 3

    website_id = ReviewWebsite.objects.only('id').get(id=site_id)
    comment = Comment.objects.create(comment_title=title, 
comment_content=content, comment_score=score
                                     , comment_date=review_date, 
website=website_id)

    comment.save(force_insert=True)



Output:
===================AGODA PAGE NUMBER: 1
Review: 1
    Title: Great food and great view!!!”
    Comment: Great food and great view!!! We will definitely come back!!!
    Score: 8.0
    Date: December 03, 2017
    Website: agoda
UNIQUE constraint failed: seleniumapp_comment.id


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6e8dd3c6-f286-499f-aeb7-320d6f871fcb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to