My Django application is working just fine on localhost, but when I try to push it to Heroku I get the following error:
remote: django.db.utils.ProgrammingError: multiple primary keys for table "Clientes_productlist" are not allowed
My models.py
file is:
class ProductList(models.Model):
id_new = models.IntegerField(primary_key=True)
sku = models.CharField(max_length=200)
client = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
name = models.CharField(max_length=256)
description = models.CharField(max_length=1000)
storage = models.CharField(max_length=256)
cost_price = models.CharField(max_length=256)
sell_price = models.CharField(max_length=256)
ncm = models.CharField(max_length=256)
inventory = models.IntegerField(null=True)
class Meta:
unique_together = (('sku', 'client'),)
I am using django-import-export package as well. Therefore, my resources.py
is:
class ProductListResource(resources.ModelResource):
class Meta:
model = ProductList
skip_unchanged = True
report_skipped = True
exclude = ('id',)
import_id_fields = ('sku', 'client',)
fields = ('sku', 'client', 'name', 'description', 'storage', 'cost_price', 'sell_price', 'ncm', 'inventory',)
What is causing that error and how can I solve it?
To fix that, you need to delete all the migration files in migrations
folder of the app in which ProductList
model exists, except for __init__.py
file and run ./manage.py makemigrations
to generate new migrations. Then commit those migrations and push them to Heroku.