Chris Evans
Chris Evans

Reputation: 875

Django updating model has broken the admin

I updated my models class called Account. I have removed a field called "user"

Removed this line:

user = models.ForeignKey(User, unique=True)

I then ran makemigration and then migrate successfully.

When I goto: http://127.0.0.1:8000/admin/reports/account/

I get the below error message:

Account' object has no attribute 'user'

My question is, how do I update the admin code easily when making structural changes to my models/migration?

My admin.py looks like this:

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from .models import Account
from .models import Report

from django.contrib import admin

# Register your models here.

admin.site.register(Account)
admin.site.register(Report)

Upvotes: 0

Views: 311

Answers (2)

Jahongir Rahmonov
Jahongir Rahmonov

Reputation: 13763

Well, you probably forgot to remove user reference somewhere, possibly in admin.py. If you go there, there should be something like this (if not, post yours):

@admin.register(Account)
class AccountAdmin(admin.ModelAdmin):

    list_display = ('user', ...)

Just remove the user from there and you should be good.

Upvotes: 0

Astik Anand
Astik Anand

Reputation: 13057

It is a bit complex process.

The easier way is if you don't have any important data and you are only in development phase, just delete your database, and try makemigrations and migrate after that.

It will work fine.

Upvotes: 1

Related Questions