Hi All,
I think issue is may be wrong relationship settings in my model file but couldn't able to find exact issue.
Let me know if need any more info from side.
-- I have created a simple database admin panel (Django2..6+Python3.6+Mysql5.7) where admin can operate create/edit/delete operations of database.
I am facing following IntegrityError error when I try to Merge two products and click on Preview from my Django admin panel-
2018-07-02 16:17:56,428 [ERROR] exception.py:118 handle_uncaught_exception() : Internal Server Error: /where2buy/merchantproduct/Traceback (most recent call last): File "C:\Users\prateek1.gupta\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\backends\utils.py", line 85, in _execute return self.cursor.execute(sql, params) File "C:\Users\prateek1.gupta\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute return self.cursor.execute(query, args) File "C:\Users\prateek1.gupta\AppData\Local\Continuum\anaconda3\lib\site-packages\MySQLdb\cursors.py", line 250, in execute self.errorhandler(self, exc, value) File "C:\Users\prateek1.gupta\AppData\Local\Continuum\anaconda3\lib\site-packages\MySQLdb\connections.py", line 50, in defaulterrorhandler raise errorvalue File "C:\Users\prateek1.gupta\AppData\Local\Continuum\anaconda3\lib\site-packages\MySQLdb\cursors.py", line 247, in execute res = self._query(query) File "C:\Users\prateek1.gupta\AppData\Local\Continuum\anaconda3\lib\site-packages\MySQLdb\cursors.py", line 411, in _query rowcount = self._do_query(q) File "C:\Users\prateek1.gupta\AppData\Local\Continuum\anaconda3\lib\site-packages\MySQLdb\cursors.py", line 374, in _do_query db.query(q) File "C:\Users\prateek1.gupta\AppData\Local\Continuum\anaconda3\lib\site-packages\MySQLdb\connections.py", line 277, in query _mysql.connection.query(self, query)_mysql_exceptions.IntegrityError: (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`productsearchv2`.`feed`, CONSTRAINT `feed_mproduct_id_fk` FOREIGN KEY (`merchant_id`, `merchant_product_id`) REFERENCES `merchant_product` (`merchant_id`, `merchant_product_id`) ON DELETE NO )')I think issue is may be wrong relationship settings in my model file but couldn't able to find exact issue.
Can anyone please help me to find the issue? My code is as below-
class MerchantProduct(models.Model):
merchant = models.ForeignKey(Merchant, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.SET_NULL, blank=True, null=True)
merchant_product_id = models.CharField(max_length=100)
gtin = models.CharField(max_length=15, blank=True, null=True)
merchant_group_id = models.CharField(max_length=100, blank=True, null=True)
name = models.CharField(max_length=300)
description = models.TextField(blank=True, null=True)
image_urls = models.TextField(blank=True, null=True)
image_phashes = models.TextField(blank=True, null=True)
web_url = models.URLField(blank=True, null=True)
brand = models.CharField(max_length=100, blank=True, null=True)
category = models.CharField(max_length=150, blank=True, null=True)
color = models.CharField(max_length=100, blank=True, null=True)
size = models.CharField(max_length=100, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True, editable=False)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
unique_together = (('merchant', 'merchant_product_id'),)
managed = False
db_table = 'merchant_product'
def __str__(self):
return self.name
class Product(models.Model):
merchants = models.ManyToManyField(Merchant, through='MerchantProduct')
brand = models.ForeignKey(Brand, related_name='brand', on_delete=models.SET_NULL, blank=True, null=True)
category = models.ForeignKey(Category, related_name='category', on_delete=models.SET_NULL, blank=True, null=True)
group = models.ForeignKey('self', related_name='ID', on_delete=models.SET_NULL, blank=True, null=True)
gtin = models.CharField(max_length=15, blank=True, null=True)
name = models.CharField(max_length=300)
description = models.TextField()
image_urls = models.TextField()
image_phashes = models.CharField(max_length=200, blank=True, null=True)
color = models.CharField(max_length=100, blank=True, null=True)
size = models.CharField(max_length=100, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True, editable=False)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
managed = False
db_table = 'product'
def __str__(self):
return self.name
class Merchant(models.Model):
DATA_QUALITY_CHOICES = (
('approx', 'Approximate'),
('exact', 'Exact'),
)
name = models.CharField(unique=True, max_length=45)
display_name = models.CharField(unique=True, max_length=255)
url_name = models.CharField(unique=True, max_length=255)
data_quality = models.CharField(default='approx', max_length=6, choices=DATA_QUALITY_CHOICES)
status = models.CharField(default='I', max_length=1, choices=STATUS_CHOICES)
featured_rank = models.PositiveSmallIntegerField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True, editable=False)
updated_at = models.DateTimeField(auto_now=True)
config = models.TextField(default='{}', max_length=500, blank=True, null=True)
class Meta:
managed = False
db_table = 'merchant'
def __str__(self):
return self.name
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/5a9c9084-b1ab-4c34-8fd6-931101293428%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment