Last modified: Jan 10, 2023 By Alexander Williams
How to Solve django.contrib.admin.sites.AlreadyRegistered
The django.contrib.admin.sites.AlreadyRegisteredissue appears when you're trying to register a model that is already registered in the app.
In this tutorial, we'll see an example of the issue and how to solve it.
django.contrib.admin.sites.AlreadyRegistered Example
from django.contrib import admin
#models
from .models import *
# Register your models here.
admin.site.register(Topic)
admin.site.register(Topic)
Output:
django.contrib.admin.sites.AlreadyRegistered: The model Topic is already registered in app 'core'.
As you can see, we've registered the Topic model twice.
Solving django.contrib.admin.sites.AlreadyRegistered
To solve this issue, we need to remove the duplicate line.
from django.contrib import admin
#models
from .models import *
# Register your models here.
admin.site.register(Topic)
Output:
System check identified no issues (0 silenced). June 08, 2021 - 00:33:31 Django version 3.2.1, using settings 'app.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.