Hello Rich,
Unfortunately the migration framework is not smart enough to resolve this kind of dependency.
The order of operation/migrations of the makemigrations is generated by the autodetector which
hardcodes most of its logic.
I would have assumed that constraints were generated _after_ unique_togethers though[0].
I suspect the operations are ordered this way because the index and constraints operations don't
implement the references_field and references_model operations.
Could you give a try at implementing them for `AddConstraint` based on your CompositeForeignKey
values and see if it helps anyhow?
They should likely be implemented in core but I suspect it will be hard for functional and conditional
indices just like constraints are. I think the best way forward will be to add a `referenced_fields`
property on Index and BaseConstraint that returns a set of (model_label, field_name) tuples and
have index and constraint operations rely on them.
Cheers,
Simon