Don't try to apply defaults to certain database-specific field types.

Review Request #12283 — Created May 16, 2022 and submitted — Latest diff uploaded

Information

Django Evolution
release-2.x

Reviewers

On MySQL, text, blob, json, and the short/medium/long
varieties of the first two are forbidden from having default values.

Django Evolution would try to apply these anyway when adding a non-NULL
field or changing a field to be non-NULL (and in fact validated that
such a value would be provided when setting to non-NULL). This would
prevent these types of fields from being added unless they were set to
allow NULL.

Now, the evolution op backends can override a
get_field_type_allows_default() method, which can check a field to
determine if default values should be allowed. This is used when
building a column schema definition, ensuring that any DEFAULT-related
SQL is omitted if not allowed for the field.

Unit tests pass for all supported database types on all supported
versions of Django.

Diff Revision 1 (Latest)

Commits

First Last Summary ID Author
Don't try to apply defaults to certain database-specific field types.
On MySQL, `text`, `blob`, `json`, and the `short`/`medium`/`long` varieties of the first two are forbidden from having default values. Django Evolution would try to apply these anyway when adding a non-NULL field or changing a field to be non-NULL (and in fact validated that such a value would be provided when setting to non-NULL). This would prevent these types of fields from being added unless they were set to allow NULL. Now, the evolution op backends can override a `get_field_type_allows_default()` method, which can check a field to determine if default values should be allowed. This is used when building a column schema definition, ensuring that any `DEFAULT`-related SQL is omitted if not allowed for the field.
bc10ee5cd1e1e7f37386944cc075be832b79e397 Christian Hammond
django_evolution/db/common.py
django_evolution/db/mysql.py
django_evolution/tests/test_add_field.py
django_evolution/tests/db/mysql.py
django_evolution/tests/db/postgresql.py
django_evolution/tests/db/sqlite3.py
Loading...