[Fixed]-Django UNIQUE constraint failed with OneToOneField while migrate in Django User Model

1👍

You should change the relation with Blog model, as one Person can write more than 1 blog, hence its a 1-M relation. So in Blog model you should define a ForeignKey to Person model.

person = models.ForeignKey(
        'person.Person',
        related_name='walls'    
    )

And wall field will be removed from Person model, but from person objects you will be able to access blogs using related name walls.

If your have a necessity of having Person to Blog as 1-1 relation, then your will have to remove records from database which don’t follow this constraint.

Leave a comment