Repository navigation
Conversation
|
Never mind, just saw your original comment |
|
Looks like it doesn't work for all db types |
|
Yes, that syntax unfortunately only works for PG. I have some more ideas, more is coming |
|
Both checks together, then it works - at least with Postgres and SQLite. |
There was a problem hiding this comment.
There was a problem hiding this comment.
@miggland is there reason for using raw SQL or can we use at least the schema_editor? Pure Mysql can not to "IF EXISTS"
There was a problem hiding this comment.
schema_editor looks appropriate, I was not aware of this, should have done that to start with
There was a problem hiding this comment.
I did not try it, and kept it from @SchrodingersGat original implementation.
However, since Django seems to not realise that the field is there (the reason #4977 doesn't quite work), I suspected using RemoveField wouldn't work either.
There was a problem hiding this comment.
It seems I suspected correctly - since the fields do not show up in the list, RemoveField does not do anything - just like checking for the field in the list.
|
The suggested changes fix the myqsl migrations on mysql and mariadb; on-prem and on github (docker running on ubuntu 20.04) |
|
Another option: The original PR which broke this renamed So, for anyone who ran Anyone who did not run this (now deleted) migration is fine. So, can we check if there is an entry in the migration log for this file? |
|
@SchrodingersGat that should also be possible |
Co-authored-by: Matthias Mair <[email protected]>
Did you actually test this out, by going from a state before the botched migration to this? When I do that (see #4977 for details) I get this: |
|
I've added another suggestion, which should work for MySQL even on an existing DB. @matmair Could you double-check that this doesn't break the test in mysql? |
|
Why do we want to put such a potentially unsafe operation in a migration that runs on every fresh install? I would propose to not include such doctoring in the migration chain. Instead I would consider starting a doctor management command that can be used to fix the database whenever such an migration issue occur. E.g. gitea has such a doctor command. |
|
@wolflu05 I agree it is far from ideal but we have to make it seamless for the user. |
|
@miggland your latest patch works for me on postgresql. I can successfully:
|
Awesome. Had not tried migrating backwards, but I did try it on postgres, sqlite and mysql in docker, going from before to after the broken migration. |
|
@miggland @matmair FYI I have an alternative approach which does not require any custom SQL |
|
@miggland other PR is merged, feel free to close this out now |

See #4977