Commit 6275ca6
committed
Accept deferrable kwarg for schema editor SQL
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.1 parent d166fc9 commit 6275ca6
1 file changed
+12
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
677 | 677 | | |
678 | 678 | | |
679 | 679 | | |
680 | | - | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
681 | 690 | | |
682 | 691 | | |
683 | 692 | | |
| |||
694 | 703 | | |
695 | 704 | | |
696 | 705 | | |
697 | | - | |
| 706 | + | |
698 | 707 | | |
699 | 708 | | |
700 | 709 | | |
701 | 710 | | |
702 | 711 | | |
703 | 712 | | |
704 | 713 | | |
705 | | - | |
| 714 | + | |
706 | 715 | | |
707 | 716 | | |
708 | 717 | | |
| |||
0 commit comments