| 8 | |
| 9 | In summary the statement issues on `ForeignKey` addition before this change on recent versions of MySQL were along the lines of |
| 10 | |
| 11 | {{{#!sql |
| 12 | -- < Django 3.0 with explicit ALGORITHM |
| 13 | ALTER TABLE foo ADD COLUMN bar_id integer, ALGORITHM=INSTANT; |
| 14 | ALTER TABLE foo ADD CONSTRAINT bar_id_fk FOREIGN KEY foo(bar_id) REFERENCES bar(id), ALGORITM=COPY; |
| 15 | |
| 16 | -- >= Django 3.0 with explicit ALGORITHM |
| 17 | ALTER TABLE foo ADD COLUMN bar_id integer, ADD CONSTRAINT bar_id_fk FOREIGN KEY foo(bar_id) REFERENCES bar(id), ALGORITM=COPY; |
| 18 | }}} |
| 19 | |
| 20 | On a side note we've noticed that having the MySQL backend wrap foreign key constraint creation with `SET foreign_key_check=0` and `SET foreign_key_check=1` will allow the usage of `ALGORITHM=INPLACE` which might be a desirable behaviour to add in core since the schema editor can guarantee that no constraint violations will happen in the current session while adding the constraint. |