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...
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',
}
}
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With