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

2

6

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)
Garris answered 1/11, 2017 at 14:6 Comment(11)
How do the migrations look that are created for this app?Ahlgren
@schwobaseggl Here is what 'manage.py migrate' currently says: Operations to perform: Apply all migrations: accounts, admin, auth, contenttypes, manage_listings, sessions Running migrations: No migrations to apply.Garris
Can you post the content of accounts/migrations/0001_initial.py?Ahlgren
I should also mention AgentBasicInfo is attached to a ModelForm, and the ModelForm is being used in a function-based view which is handling 2 different forms.Garris
@schwobaseggl Just postedGarris
delete the database and try to run migrate again. Don't makemigrations it looks fine alreadyFormicary
What is the output of manage.py showmigrations?Ahlgren
@ArpitSolanki I installed django_extensions then used 'manage.py reset_db', then run 'manage.py' and it worked. Thank you!Garris
@schwobaseggl Posted. I followed Arpit's recommendation and it worked. Something was messed up in the database and a reset did the trick. Thanks for your help!Garris
I'm still getting this error. I cannot update the actual database table to fix the Django error. 1) Did inspectdb 2) Added 2 apps - 1 that has working ORM mappings, and one that's new. I have a new table, that I need to get ORM to the new app. However, when I do a 'migrate' (providing new_app, it says no migrations to apply) it applies it only to the old app that was part of the original project. I deleted the migration mappings from django_migrations and re-added the 'migrate' and still see that the new mapping, in the new app doesn't work! Wasted a whole day on this!Beneficiary
the migrations shows the new table, the list of migrations (showmigrations) shows the new app has the table mapping. Yet, when I try using it in a view, nothing works!!!Beneficiary
C
1

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.

Chip answered 1/11, 2017 at 14:32 Comment(0)
S
0

I also had this problem and tried:

python manage.py dbshell

But then I got this error:

CommandError: You appear not to have the 'psql' program installed or on your path.

This was due windows not finding psql in my environment path. As an alternative, you can get it done by reverting changes (that is if you had previous changes in you git repository.

For me I used this method:

git checkout <commit hash> (which did not have the error)

After that pull the changes:

git pull <remote> <branch>

Then finally:

git push origin main

Hope this helps for the ones with git repositories. I welcome any corrections.

Sweater answered 28/1, 2021 at 21:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.