ProgrammingError - relationship does not exist

462 views
Skip to first unread message

Stathis Angelou

unread,
Jul 6, 2021, 8:16:22 PM7/6/21
to Django users
Good evening all, i have created a new app and added a model. Added the app under installed apps, and run python manage.py makemigrations and migrate and everything worked as expected.

But i believe there is an issue with the admin.py file

from django.contrib import admin

# Register your models here.
from django.contrib.gis.admin import OSMGeoAdmin
from .models import Shop

@admin.register(Shop)
class ShopAdmin(OSMGeoAdmin):
    list_display = ('name', 'location')

Error message:
"ProgrammingError at /admin/shops/shop/relation "shops_shop" does not exist LINE 1: SELECT COUNT(*) AS "__count" FROM "shops_shop" "

Any advice or hint would be really appreciated 
Kind Regards

Stathis 

Jacob Greene

unread,
Jul 6, 2021, 8:52:35 PM7/6/21
to django...@googlegroups.com
The issue is with the model not the admin page. I suspect you haven't ran migrations for the "Shop" model. You defined a "shop" field in the model, but the database doesn't know anything about it.



--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/60ca7670-d423-49e1-9d4a-ea978e193dd4n%40googlegroups.com.

Stathis Angelou

unread,
Jul 7, 2021, 4:49:01 AM7/7/21
to Django users
Good morning Jacob and thank you for your reply, i really do appreciate your time in looking into this, I am attaching my 

models.py:
# Create your models here.
from django.contrib.gis.db import models

class Shop(models.Model):
    name = models.CharField(max_length=100)
    location = models.PointField()
    address = models.CharField(max_length=100)
    city = models.CharField(max_length=50)

and showmigrations 
admin
 [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
 [X] 0003_logentry_add_action_flag_choices
auth
 [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
 [X] 0004_alter_user_username_opts
 [X] 0005_alter_user_last_login_null
 [X] 0006_require_contenttypes_0002
 [X] 0007_alter_validators_add_error_messages
 [X] 0008_alter_user_username_max_length
 [X] 0009_alter_user_last_name_max_length
 [X] 0010_alter_group_name_max_length
 [X] 0011_update_proxy_permissions
 [X] 0012_alter_user_first_name_max_length
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
sessions
 [X] 0001_initial
shops
 [X] 0001_initial
 [X] 0002_auto_20210630_1341

does this give you a better idea?
Thank you very much again
Stathis

Lalit Suthar

unread,
Jul 7, 2021, 7:44:40 AM7/7/21
to django...@googlegroups.com
If this is your personal project delete all migrations inside shops app and run makemigrations, migrate again
Not sure but this may work I had similar error some time ago

Samin Serge

unread,
Jul 7, 2021, 9:14:12 AM7/7/21
to django...@googlegroups.com
in admin.py put this code to see. 
@admin.site.register (shop) 


--

Jacob Greene

unread,
Jul 7, 2021, 12:04:39 PM7/7/21
to django...@googlegroups.com
Do you have any other attributes set in the modeladmin? Something is telling the ORM to do a query on the "shop" field, and that field doesn't exist in the DB and it's not defined in the model. Possibly a filter field in the ModelAdmin class? A full back trace might help illuminate where you have this set.

Jacob Greene

unread,
Jul 7, 2021, 12:07:50 PM7/7/21
to django...@googlegroups.com
Oh actually, it looks like the table doesn't exist. I misread the SQL. Something is wrong with your migrations. Are you sure you ran "makemigrations" after creating the shop model?

Stathis Angelou

unread,
Jul 7, 2021, 7:17:34 PM7/7/21
to Django users

Good evening all and thank you for your messages,

 as suggested i did delete all migrations in my shops project and did do them again,
but i'm getting the same error message, i did use again makemigrations and migrate.
show migrations show everything applied ok. if it makes it easier for you i can share my github repository:
https://github.com/sangel667/Nearby_Shops_Project

Once again thank oyu very much for your time

Stathis

Lalit Suthar

unread,
Jul 8, 2021, 3:01:32 AM7/8/21
to django...@googlegroups.com
you can try this https://stackoverflow.com/questions/26283159/django-1-7-migrations-how-do-i-clear-all-migrations-and-start-over-from-scrat#comment41239691_26283159
if that also doesn't work and you are working on a personal project then you can try deleting your db, migration files and re running migrations

Stathis Angelou

unread,
Jul 13, 2021, 6:56:27 AM7/13/21
to Django users
Good morning all and thank you for your time in this, as suggested once again I did delete my migrations and re-run them again, 
I am still getting the same error message though and that is when I try to add data to my app.

as mentioned before you can find my code on the link below:

Thank you once more very much

Stathis

Stathis Angelou

unread,
Jul 21, 2021, 7:35:33 PM7/21/21
to Django users
good evening all, I was wondering whether any of you had the chance to review my code and identify what the issue seems to be
Thank you once again
Stathis

Reply all
Reply to author
Forward
0 new messages