Hi Andrew and Marcin,
On 07/15/2015 05:10 PM, Andrew Godwin wrote:
> Django persists every single field attribute change, no matter what it
> is - this was a deliberate decision as we didn't want to declare certain
> attributes as "not important for schema" (for example, a subclass of
> ChoiceField might use an enum column type for the choices and so need
> that change).
There's another reason for this choice: accuracy of the "historical" or
"frozen" ORM used in data migrations. Even if a field attribute has no
effect on the database schema, it could have a significant effect on the
Python-level behavior in a data migration. For instance, it's entirely
possible that a data migration could use a `get_FOO_display` method,
which could certainly break if the choices on that field at that point
in "migration time" are not correctly preserved in the migrations.
> That said, this is definitely a common problem and I'm starting to think
> we should revisit it - specifically, have field classes themselves say
> which attributes are not worth making changes for (perhaps combined with
> greater control by fields over how their schema gets made). This isn't
> currently possible though.
If we do this, I think it should be opt-in and used only by the end
developer for unusual cases (like dynamic choices). The default should
continue to be to preserve all field attributes, including choices, for
frozen-ORM reasons.
Carl