Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProgrammingError at "url" relation "app_model" does not exist LINE 1: SELECT COUNT(*) AS "__count" FROM "app_model"

I've searched every Stack Overflow question on this error but none of the responses helped. I'm getting this error when trying to access the admin page of this particular model (AgentBasicInfo).

'manage.py makemigrations' works fine. 'manage.py migrate' also works fine. 'manage.py runserver' works fine, the whole website works fine until I try to go onto the admin page of this model.

The app is correctly installed in INSTALLED_APPS in settings.py. I am using Postgres for the database.

I have tried...

  1. Deleting migrations and re-running makemigrations/migrate
  2. Deleting the entire migrations folder for this app and rerunning makemigrations/migrate
  3. Deleting all the migrations from all my apps and re-running makemigrations/migrate
  4. I have tried running 'manage.py migrate' and 'mangae.py migrate app_name'. I still get the same error.

This model (see code below) is quite basic. I have several other models in my project and they work just fine in the admin, but just this particular model doesn't work.

models.py

class AgentBasicInfo(models.Model):

    preferred_email = models.EmailField()
    office_phone_number = models.IntegerField()
    brokerage_of_agent = models.CharField(max_length=50)
    agent_title = models.CharField(max_length=20)

    def __str__(self):
        return self.preferred_email

settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'postgres',
        'USER': 'postgres',
        'PASSWORD': 'lagger123',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

Picture of the error for reference

0001_initial.py

from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='AgentBasicInfo',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('preferred_email', models.EmailField(max_length=254)),
                ('office_phone_number', models.IntegerField()),
                ('brokerage_of_agent', models.CharField(max_length=50)),
                ('agent_title', models.CharField(max_length=20)),
            ],
        ),
    ]

Output of manage.py showmigrations:

accounts
 [X] 0001_initial
admin
 [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
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
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
coresite
 (no migrations)
databases
 (no migrations)
manage_listings
 [X] 0001_initial
search_listings
 (no migrations)
sessions
 [X] 0001_initial
teams
 (no migrations)
like image 359
Valachio Avatar asked Nov 01 '17 14:11

Valachio


1 Answers

Open db command line.

python manage.py dbshell

And try this

delete from django_migrations where app='app_name';

Then delete migration files and run migration commands.

like image 104
Abhijith Asokan Avatar answered Oct 13 '22 22:10

Abhijith Asokan