[Django]-How to fix: "RuntimeWarning: Model <my_model> was already registered."

34👍

Exactly the same problem had happened to me. The problem was that I had defined a model twice! Removing one of them solved the problem.

5👍

Check in your models if you don’t got a duplicate class model, sometimes when we make a rebase or merge in our existing branches, our code can be duplicated, i had the same problem, isn’t a big deal.

4👍

I got the same error when mistakenly defining 2 of the same name models(classes) in "models.py" as shown below:

# "models.py"

from django.db import models

class Product(models.Model):
    name = models.CharField(max_length=100)

class Product(models.Model):
    title = models.CharField(help_text=_("Required"), max_length=200)

2👍

I have gotten this error because of automatic imports I had in my __init__.py. I had some old code that imported by signals there, and moving that import code to AppConfig instead fixed it.

1👍

It is saying that you have already registered the model before
Hence by deleting the second model or writing the code in the specified model is the solution for this .

👤ganesh

Leave a comment