-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
[fix] deviceconnection_unique_together fails due to duplicate objects #861
[fix] deviceconnection_unique_together fails due to duplicate objects #861
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works on sqlite but as I feared, on PostgreSQL it throws this error:
django.db.utils.OperationalError: cannot ALTER TABLE "connection_deviceconnection" because it has pending trigger events
We have found out in prod that performing data migrations and schema migrations in the same migration class doesn't work well on Postgres.
Setting the atomic
attribute to False
has worked in my tests but it's, if anything goes wrong we will run into serious database consistency issues, it's not worth the risk.
The only reliable solution is to split the migration files:
- the first migration file should do the data migration
- the second data migration will perform the schema change
It will cause a bit of pain to whoever is using the dev version, because they will likely have already executed the existing migration, and running these new migrations will result into an error, but fixing that is as easy as running ./manage.py migrate connections --fake
and I don't see any safer solution.
openwisp_controller/connection/migrations/0008_alter_deviceconnection_unique_together.py
Outdated
Show resolved
Hide resolved
@nemesifier can you review it again |
openwisp_controller/connection/migrations/0008_remove_conflicting_deviceconnections.py
Outdated
Show resolved
Hide resolved
595c772
to
ad99f7b
Compare
Fixes #846