Question

I changed the model, synced the db, and now when i do:

Prs = Products.objects.filter(PrName__icontains='bla')

I get the error:

    ERROR:  column search_products.pr_name does not exist
LINE 1: SELECT "search_products"."id", "search_products"."pr_name", ...

But pr_name was the old model, this is how the new model looks like:

class Products(models.Model):
  PrName = models.CharField(max_length=255)
  PrDescription = models.CharField(max_length=4000)
  PrPrice = models.DecimalField(max_digits=5, decimal_places=2)
  PrCompany =  models.ForeignKey(Companies)

  def __str__(self):
    return self.PrName

Why am i getting this error? I synced the db 100 times, checked all the code, there is no reference to pr_name anywhere?

Was it helpful?

Solution

Have you tried restarting your server? If you are using anything other than the development server, you'll probably need to do that manually after making changes like this.

OTHER TIPS

Unfortunately the thing you try to do is not supported by django out of the box :-(

but you can do it ether by adding a db_column to the fields or by exporting the data, removing the table from the database, edit the export file, recreate the database table and reimporting the data.

Also look at the various schema evolution solutions out there

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top