Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProtectedError on clean step if model is referenced throught a protected Foreign key #50

Open
chinskiy opened this issue Mar 28, 2020 · 0 comments
Labels

Comments

@chinskiy
Copy link
Member

In cases like

class Musician(models.Model):
    instrument = models.CharField(max_length=100)

class Album(models.Model):
    artist = models.ForeignKey(
        'app.Musician',
        on_delete=models.PROTECT
    )

Order matters for cleaning models

For example

from dj_anonymizer import register_models

register_models.register_clean([
    Musician, Album
])

Will raise

django.db.models.deletion.ProtectedError: ("Cannot delete some instances of model 'Musician' because they are referenced through a protected foreign key: ...

And in case

from dj_anonymizer import register_models

register_models.register_clean([
    Album, Musician
])

All will be good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant