Skip to content

Conversation

@kummerer94
Copy link
Owner

No description provided.

sparrowt and others added 10 commits April 18, 2020 15:06
Ensure that the unique/unique_together constraint is
reinstated exactly the same as the one that was dropped
earlier in `_alter_field`

This fixes both cases described on the bug report, that
is when `AlterField` modifies a column which is:
 1) individually `unique=True` as well as `null=True`
 2) in a `unique_together` where at least 1 column is nullable
- Support for JSONField
- Updates parameter structure for sql_flush - reset_sequences
- Add an mssql specific feature flag - supports_order_by_is_nulls
This follows Django 3.1.x's lead in adding `deferrable` as a keyword
argument to the `_create_unique_sql` function, following their
implementation in the schema editor object.  Without accepting this
keyword arg, migrations will crash like so:

```
...
  File "lib/python3.8/site-packages/django/db/backends/base/schema.py", line 360, in add_constraint
    sql = constraint.create_sql(model, self)
  File "lib/python3.8/site-packages/django/db/models/constraints.py", line 118, in create_sql
    return schema_editor._create_unique_sql(
TypeError: _create_unique_sql() got an unexpected keyword argument 'deferrable'
```

This also adjusts the implementation to call
`self_deferrable_constraint_sql(...)` with the deferrable arg; in this
backend's case the return value is an empty string (like it is currently
hardcoded).  Essentially it's the same result but allows flexibility if
this backend ever supported deferrable constraints.

Backwards compatibility is maintained by checking for the passing of a
deferrable keyword argument to the create sql function (not provided on
earlier Django versions before 3.1) and that the database backend
supports deferral for unique indexes.
@kummerer94 kummerer94 merged commit a738f41 into kummerer94:master Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants