Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Django – ProgrammingError – column does not exist

I normally find a solution around this problem. I even tried the nuclear option of resetting the data base completely with python manage.py flush but no luck. (I have also tried by deleting the migrations folder, but again no result)

the exact error message is the following:

column main_reviewrating.venue_id does not exist

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Maybe it’s the first time I pay attention to this but the venue**_id** seems strange.

I am quite sure the usual message would have something like

main_reviewrating.venue (without the _id

When I run python manage.py showmigrations <your_app_name> it does show

[X] 0001_initial

I should also add that I am running this on my local, so no problem specific to deployment.

Here is the code (models.py)

class Venue(models.Model):
    name = models.CharField(verbose_name="Name",max_length=100, null=True, blank=True)
   
    def __str__(self):
        return str(self.name) if self.name else ''

class Product(models.Model):
    name = models.CharField('Product Name', max_length=120, null=True)

    class Meta:
        db_table='Product'
    def __str__(self):
        return str(self.name)

class ReviewRating(models.Model):
    user = models.ForeignKey(User,blank=True, on_delete=models.CASCADE, related_name="usercomments")
    product=models.ForeignKey(Product,related_name="comments", on_delete=models.CASCADE)
    review =models.TextField(max_length=250)
    rating =models.IntegerField(choices=RATING, default=0)
    venue = models.ForeignKey(Venue, blank=True, null=True, related_name="venues", on_delete=models.CASCADE)


    def __str__(self):
        return '%s - %s'%(self.user, self.product)

Any idea what I am doing wrong?

Edit: on a second thought, maybe I am using the ForeignKey wrong. What I am trying to do here is to link a specific review, of a specific product to a specific venue.

This means, the same product could be reviewed by the same user in a different venue.

>Solution :

1.Delete your database like something.sqlite3 (for backup you may rename it).

2.Delete all migration file except __init__.py.

3.Run the migrations command again.

Hopefully you will get no issue.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading