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
Fixed -- 28785 Made makemigrations warn if migrations are missing #14246
Conversation
Thanks for this ! IMO, this check should not only run for makemigrations, but also for other commands (e.g. runserver, createsuperuser, etc.) For unapplied migrations, management/base.py produces this warning :
Both cases are quite similar, so having the same type of warning for both would make sense. Can we have something like :
|
This sounds vague. I would rather the author stick to the scope of the ticket as accepted. Doing so helps both authors and reviewers. |
I don't know what's vague in my comment (maybe the wording, I'm not a native English speaker, sorry). Management commands even have a
This exactly matches the scope of what this PR is about, doesn't it ? |
Ah, thanks for clarifying. Your wording was fine. 👍🏻 It just took a second read through the ticket for me to see that the makemigrations command was not singled out until after the ticket was originally accepted, my apologies. |
Thanks, excellent find. In case helpful for others, here's the status quo for that property on various commands:
@manav014 with that in mind, do you have an opinion about how to proceed here? I would need to think more myself. The first comment on the ticket cautions this might pester folks who turn squashed migrations into normal ones, so I'm hesitant to patch this into Another thing is that we have ticket-26760 for dropping migrations from the db when they don't exist on disk, and some discussion about whether to execute that automatically vs. manually. That would make this situation less frequent, no? Thanks for your input @olivierdalang; good find, and once again, apologies if I sounded out of breath earlier. |
@jacobtylerwalls Are you referring to this ? django/docs/topics/migrations.txt Lines 816 to 822 in bd9cfbb
That's indeed a case where the warning would show. But I'm not sure the docs give a good advice there (is it mandatory to remove As for this PR, maybe it could add a line in that part of the docs warning that doing that process would lead to warnings displaying at users. And the warning itself could mention the case of squashed migrations and suggest to remove the rows in the migration tables if that's the case. It's a bit hard to tell how frequently this is being used. All in all, I think it's a deeper issue in the squashing process (alongside other issue with it, see https://groups.google.com/g/django-developers/c/xpeFRpMTBZw/m/lDq78EedAwAJ), and I'd see this PR as beneficial anyways as it could actually help highlight some existing potential issues, including the one mentioned in ticket 26760. |
@jacobtylerwalls I think I need to dig more into this. But as of now, What I have in mind is that we shall use |
Yep, you found the right bit in the docs re: "transition the squashed migration to a normal migration".
Recent triage decisions have stuck to this literal advice that it's mandatory, see ticket-32205. |
Nice, that sounds like a good start. Then we can get a decision on |
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.
@manav014 Thanks for this patch 👍
I'm afraid that we cannot move it forward without solving ticket-26760, because it will raise warnings for squashed migrations which were removed.
', '.join(repr(app) for app in sorted(deleted_migration_al))) | ||
elif any(apps in app_labels for apps in deleted_migration_al): | ||
raise InconsistentMigrationFileHistory( | ||
', '.join(repr(app) for app in sorted(deleted_migration_al) if app in app_labels)) |
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.
I would prefer the solution from #9339 where we list all missing files not only all labels.
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.
I will commit the desired changes.
@@ -285,6 +285,24 @@ def build_graph(self): | |||
raise | |||
self.graph.ensure_not_cyclic() | |||
|
|||
def check_consistent_migration_files(self, connection, app_labels): |
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.
Do we need app_labels
? IMO it should be fine to check all apps like in check_consistent_history()
.
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.
I will commit the desired changes.
@felixxm Thank you for your feedback. |
Hi @manav014 just a note to say ticket-26760 was recently fixed with a feature to call |
Thanks, @jacobtylerwalls . I will add a warning message to warn the user about |
Closing due to inactivity. |
ticket-28785
Supersedes #9339