I have faced a problem while working with django models. lets say my apps name is GasNet and my models name is Riser well the generated table name is GasNet.riser, I can successfully generate table and add objects to table and even delete all of the objects of a table. But when I try to delete an object I face this error
The above exception (relation "GasNet_riser" does not exist LINE 1: ..."."createDateTime", "GasNet_riser"."deleted" FROM "GasNet_ri... ^ ) was the direct cause of the following exception:in debug window the sql query is as
sql ('SELECT "GasNet_riser"."id", "GasNet_riser"."city_code", ' '"GasNet_riser"."geom"::bytea, "GasNet_riser"."node_code", ' '"GasNet_riser"."pipe", "GasNet_riser"."parcel_code", ' '"GasNet_riser"."Number", "GasNet_riser"."hack", "GasNet_riser"."multi_code", ' '"GasNet_riser"."gis_code", "GasNet_riser"."angle", "GasNet_riser"."size", ' '"GasNet_riser"."direction", "GasNet_riser"."instalation_date", ' '"GasNet_riser"."description", "GasNet_riser"."type", ' '"GasNet_riser"."status", "GasNet_riser"."instalation_type", ' '"GasNet_riser"."material", "GasNet_riser"."zone_id", ' '"GasNet_riser"."prejenti_id", "GasNet_riser"."emergency_sub_zone_id", ' '"GasNet_riser"."updateDateTime", "GasNet_riser"."createDateTime", ' '"GasNet_riser"."deleted" FROM "GasNet_riser" WHERE "GasNet_riser"."id" = %s')this is my model
class Riser(models.Model): id=models.AutoField(primary_key=True) city_code = models.CharField(max_length=10) geom = models.PointField(srid=4326) node_code = models.IntegerField(default=-1,blank=True) # شماره گره جهت اعمال مصرف آن برروی گره در طراحی pipe = models.IntegerField(default=-1,blank=True) parcel_code = models.IntegerField(default=-1,blank=True) Number = models.CharField(max_length=20) #کد علمک hack = models.IntegerField(default=-1,blank=True) multi_code = models.CharField(max_length=10,blank=True) gis_code = models.CharField(max_length=20,blank=True) angle = models.FloatField(default=-1,blank=True) size = models.IntegerField(default=-1,blank=True) direction = models.TextField(max_length=500,blank=True) instalation_date = models.DateField(null=True,blank=True) # تاریخ نصب description = models.TextField(blank=True) type = models.CharField(max_length=20,blank=True) # همان فیلد kind هست # choises status = models.CharField(max_length=5,default=ModelChoiseFields.NAN, choices=ModelChoiseFields.RISER_STATUS,blank=True) instalation_type = models.CharField(max_length=5,default=ModelChoiseFields.NAN, choices=ModelChoiseFields.RISER_INSTALATION_TYPE,blank=True) material = models.CharField(max_length=5,default=ModelChoiseFields.NAN, choices=ModelChoiseFields.RISER_MATERIAL,blank=True) # relations zone = models.ForeignKey(Zone,on_delete=models.CASCADE,null=True) prejenti = models.ForeignKey(pt,models.CASCADE,null=True,blank=True) emergency_sub_zone = models.ForeignKey(EmergencySubZone,models.CASCADE,null=True) # زیرناحیه امداد # Auto fields updateDateTime = models.DateTimeField('update date', auto_now_add=True, auto_now=False) createDateTime = models.DateTimeField('create date',auto_now_add=False, auto_now=True) deleted = models.BooleanField(default=False)I tried makemigrations and migrate and I know that table is fine but I have no idea why this happens.
I try to delete object using this method.
selected=Riser.objects.get(id=id) selected.delete()I think the problem is with app name and upper case G and N but I do not know how to fix this problem.
I also tried to delete using filter and the same error happens. it says
relation "GasNet_riser" does not exist LINE 1: DELETE FROM "GasNet_riser" WHERE "GasNet_riser"."id" = 1115 ^ when I run the above query manually in my database it runse with no problem DELETE FROM "GasNet_riser" WHERE "GasNet_riser"."id" = 1115 returns Query returned successfully: one row affected, 62 msec execution time.
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/b9812b1a-0585-447b-a19a-06279a6a87be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment