-------- Forwarded Message --------
Subject: Re: relation “” does not exist in django for app name with mixed-case
Date:   Wed, 6 Jun 2018 17:22:13 +0100
From:   Anthony Flury <anthony.fl...@btinternet.com>
To:     Majid Hojati <asd5...@gmail.com>



The problem isn't the name of the model. I doubt Django is going to have
an issue with standard named Python Classes.

The error is saying that Django can't find the Model in the data based.

In the Django console, and you enter this :

|selected=Riser.objects.get(id=id)|

Do you get an error ?

Have you confirmed that your Django app is pointing to the right database.

BTW - why do you think it has anything to do with the Model name being
mixed case ? The fact that you can add objects to the table suggest to
me that DJango has no problem with the table name at all ?


On 05/06/18 11:28, Majid Hojati wrote:

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 notexist LINE 1:..."."createDateTime", "GasNet_riser"."deleted" FROM "GasNet_ri...^)was the direct cause ofthe followingexception:|

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 notexist LINE 1:DELETEFROM"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+unsubscr...@googlegroups.com <mailto:django-users+unsubscr...@googlegroups.com>. To post to this group, send email to django-users@googlegroups.com <mailto: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 <https://groups.google.com/d/msgid/django-users/b9812b1a-0585-447b-a19a-06279a6a87be%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.


--
--
Anthony Flury
email : *anthony.fl...@btinternet.com*
Twitter : *@TonyFlury <https://twitter.com/TonyFlury/>*

--
--
Anthony Flury
email : *anthony.fl...@btinternet.com*
Twitter : *@TonyFlury <https://twitter.com/TonyFlury/>*

--
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+unsubscr...@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/8eed2f54-ae2f-8112-4a68-48146be40752%40btinternet.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to