[Fixed]-Django.db.migrations.exceptions.CircularDependencyError

28👍

Temporarily comment out foreign keys to break the circular dependency. It looks like you could do this by commenting out Hospital.doctor. Remove the existing migrations and run makemigrations to recreate them.

Finally, uncomment the foreign keys, and run makemigrations again. You should end up with migrations without any circular dependencies.

0👍

Should be useful if you add your Calendar model. However don’t use the inheritance without abstract modal.

class Person(models.Model):
    ...

    class Meta:
        abstract = True

0👍

Like you might have defined them as something below:

new_field = models.ForeignKey(ForeignModel, ...)

Instead do this:

new_field = models.ForeignKey("ForeignModel", ...)

0👍

  1. Delete your existing virtual environment and create a new one.
  2. In your models files, comment out all ForeignKey fields.
  3. Run migrations and migrate
  4. Uncomment the ForeignKey fields you commented
  5. Again run migrations and migrate
👤Asif

Leave a comment