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 #26739 -- Made reverse RemoveField handle non-nullable columns. #16890
base: main
Are you sure you want to change the base?
Conversation
4517c00
to
2af2a74
Compare
django/db/migrations/autodetector.py
Outdated
and not field.many_to_many | ||
and not (field.blank and field.empty_strings_allowed) | ||
and not ( | ||
isinstance(field, time_fields) |
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.
Checking the type is unnecessary. Often duck typing is used in Django; presence of auto_now or auto_now_add is enough.
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.
If I am not wrong fields other than date and time fields don't have auto_now and auto_now_add attribute. won't they throw an error if i remove type checking? It is used even in field addition, see here.
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.
Maybe let's use:
getattr(field, "auto_now", False) or getattr(field, "auto_now_add", False)
This is the same as BaseDatabaseSchemaEditor._effective_default
.
I think we have everything from BaseDatabaseSchemaEditor._effective_default
, I tested GeneratedField
case but these are covered by not field.null
.
# MySQL populates NOT NULL cols with implicit defaults instead of raising | ||
# an error. |
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.
Interesting I did not know this… I don't use MySQL but I'm hardly surprised 😛
I wonder whether this can be utilised in any way.
9761645
to
3d5abd4
Compare
3d5abd4
to
620ebda
Compare
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.
Looks like a good start to me!
The main thing I spotted is that we don't have any support for db_default
which landed recently.
620ebda
to
332edbf
Compare
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.
Thank you @DevilsAutumn! This is getting really close, got a few more comments 👍
django/db/migrations/autodetector.py
Outdated
and not field.many_to_many | ||
and not (field.blank and field.empty_strings_allowed) | ||
and not ( | ||
isinstance(field, time_fields) |
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.
Maybe let's use:
getattr(field, "auto_now", False) or getattr(field, "auto_now_add", False)
This is the same as BaseDatabaseSchemaEditor._effective_default
.
I think we have everything from BaseDatabaseSchemaEditor._effective_default
, I tested GeneratedField
case but these are covered by not field.null
.
ffd29e5
to
3884374
Compare
Ticket #26739
Thanks @MarkusH , @apollo13 and @Gagaro for initial work. (#6870 )
checklist:
ask_not_null_removal
questioner.