When running an auto-generated migration script to add new models, we always see the field order end up different to the source environment used when generating the migration script. It looks like fieldsets are always created first, which makes sense, but then the field order is not updated.
To reproduce:
Fork an environment
Add a new data model
Add a field to the model without putting it in a fieldset (e.g. a Title field)
Create a fieldset and add a field to it
Generate a migration script from the forked environment
Run the migration on a second fork and compare the data models
Expected: The models would the same
Actual: The root (title) field appears below the fieldset
Not a big deal, but means we have to create a second migration script to re-order the fields.
I probably didn’t explain it clearly enough. The problem was actually about the field that isn’t in the fieldset always appearing at the bottom of the field list.
So if I create this structure in the CMS:
Title (Text Field)
Group (Fieldset)
Field In Group (Text Field)
…and create a migration from it, after running the migration the structure becomes:
Group (Fieldset)
Field In Group (Text Field)
Title (Text Field)
It seems that all the fieldsets get created first, followed by any other ‘root’ fields.
The workaround is to then create a 2nd migration that only re-orders fields.