Home > Blockchain >  Django - ProgrammingError - column does not exist
Django - ProgrammingError - column does not exist

Time:09-03

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

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.

CodePudding user response:

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.

CodePudding user response:

Delete all files in migration folder except init.py file in your app folder and the run makemigrations.

  • Related