'relation "mains_shop" does not exist LINE 1: SELECT COUNT(*) AS "__count" FROM "mains_shop"

I am Building a Webapp and I am stuck on an Error.

What i am trying to do

I am making a GeoDjango app using Gdal , OSGeo , Postgresql , Postgis. All of them are successfuly installed.

Tutorial :- I am following this Tutorial

When i try to open the Shop panel in Django Admin then it is keep showing me

relation "mains_shop" does not exist LINE 1: SELECT COUNT(*) AS "__count" FROM "mains_shop"

And when i delete it and migrate again

then it shows

ValueError: String input unrecognized as WKT EWKT, and HEXEWKB.

But deleting migrations is solving ValueError .

models.py

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)

admin.py

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

settings.py

INSTALLED_APPS = [

   'django.contrib.gis',
]

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': '-------',
        'USER': '-------',
        'PASSWORD': '-------',
        'HOST': 'localhost',
        'PORT': '',
    }
}

What have i tried

  • First time when error appears then i think that GDal would not installed then I reinstalled it and it successfully installed.

  • I have reinstalled PostGis .

  • I have also seen many answers but nothing worked for me.

  • I have applied migrations many times.

  • I also tried python manage.py migrate --fake.

I don't know what am i doing wrong.

Any help would be appreciated.

Thank You in Advance.



Solution 1:[1]

I know this is not the best solution but it works for me. This problem occurred to me after I removed my tables in database manually.

my solution:

  1. first of all I removed all of the migration files related to the model which showed in error log. ( you should remove migrations related to Shop model)
  2. change the name of models. (you can change it to Shop2)
  3. run makemigrations and migrate command
  4. change model names back. (change it to Shop again)
  5. make migrations and migrate again

after these steps the problem fixed for me. also after these step you can delete all new migration files and make migrations again to have only one migration file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alireza Bahrololoom