#25917 closed Cleanup/optimization (fixed)
Confusing sentence in RemoveField's documentation
Reported by: | Baptiste Mispelon | Owned by: | Kai Feldhoff |
---|---|---|---|
Component: | Documentation | Version: | 1.9 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
The documentation for RemoveField
[1] states that:
if the field is not nullable this may make this operation irreversible (apart from any data loss, which of course is irreversible)
I find this sentence confusing.
The note in parentheses implies opposition with the previous statement when it's in fact saying the same thing: the operation is irreversible.
[1] https://docs.djangoproject.com/en/dev/ref/migration-operations/#django.db.migrations.operations.RemoveField
Attachments (1)
Change History (14)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
If the field is not nullable, is there a case where the reverse of RemoveField
would not fail? If not, the use of "may" is confusing.
As for the question about default
, that's a good point. I haven't tried and it could make the reverse operation "work" in the sense that Django would be able to get back to a valid state but there's no guarantee that your data would be preserved (any non-default values for that column would be gone).
comment:3 by , 9 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 9 years ago
If I see it correctly, unless Django has a value to put into a restored column from a previous migration state (e.g. default, null) RemoveField
is irreversible.
comment:6 by , 9 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:7 by , 9 years ago
It seems like everything is pretty clear here and this ticket could be finished. My suggestion for the respective section in the docs is below. As I am not a native speaker, I appreciate feedback.
By the time everything is fine, I'd like to add this to the docs being my first ticket.
Bear in mind that when reversed this is actually adding a field to a model. To make this possible, Django needs a default value to populate the recreated empty column. This is only possible for a field that is nullable or has a defined default value.
On the other hand if the field is not nullable and does not have a default value, this operation is irreversible (apart from any data loss, which of course is irreversible).
comment:8 by , 9 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:9 by , 9 years ago
Has patch: | set |
---|---|
Needs tests: | set |
comment:10 by , 9 years ago
Needs tests: | unset |
---|
Are you able to submit the patch as a pull request? That makes review easier. Please wrap documentation at 79 characters too.
comment:13 by , 9 years ago
At least it helped!
I'm having trouble to get Sphinx to work, so I was still unsure about the effect of wrapping the lines.
As I understand it, the sentence means this: if the field is not nullable, the reverse of RemoveField (adding a field) may fail, because Django does not know which data to add for existing rows.
Apart from that, the forward operation (removing the field) is of course never reversible in so far as it deletes the data in the field.
Question: would RemoveField be reversible if the field has a default value?