How to copy collection to another branch?

I have been playing with data migrations but I canā€™t figure out how to copy a collection to another branch. I tried a simple test where I use the autogenerate migration script and it give errors.

For example here I am running autogenerated script for a migration from one branch to another::
$ dato migrate --source=example --inPlace --token=
Migrations will be run in sandbox env example

  • Running 1669455966_addTestWithData.jsā€¦
    Create new models/block models
    Create model ā€œTestā€ (test)
    Warning: Attribute api_key should be expressed in camelCase syntax (apiKey)
    Warning: Attribute all_locales_required should be expressed in camelCase syntax (allLocalesRequired)
    Warning: Attribute collection_appearance should be expressed in camelCase syntax (collectionAppearance)
    Creating new fields/fieldsets
    Create Single-line string field ā€œNameā€ (name) in model ā€œTestā€ (test)
    Warning: Attribute field_type should be expressed in camelCase syntax (fieldType)
    Warning: Attribute api_key should be expressed in camelCase syntax (apiKey)
    Warning: Attribute default_value should be expressed in camelCase syntax (defaultValue)

Command failed!

Failed request:

POST https://site-api.datocms.com/item-types/[object Object]/fields

content-type: application/json
accept: application/json
authorization: Bearer token
user-agent: js-client v3.5.21
X-Api-Version: 3
x-environment: example

{ā€œdataā€:{ā€œtypeā€:ā€œfieldā€,ā€œattributesā€:{ā€œlabelā€:ā€œNameā€,ā€œfield_typeā€:ā€œstringā€,ā€œapi_keyā€:ā€œnameā€,ā€œappearanceā€:{ā€œaddonsā€:[],ā€œeditorā€:ā€œsingle_lineā€,ā€œparametersā€:{ā€œheadingā€:false}},ā€œdefault_valueā€:ā€œā€}}}

HTTP Response:

404 Not Found

Anyway, any links to working code to simply copy a collection and itā€™s data to another branch? Thanks.

Hello @jterry and welcome to the community!

Keep in mind that the auto-generation of migration scripts only supports schema changes at the moment (models and their fields) and not actual content (the records created from the models) so attempting to use auto-migration for that can generate some errors.

For content migration you would have to manually write the script, using the operations listed on our REST API: Overview - DatoCMS

If you run into any issues on writing that script, please send us an email at support@datocms.com with your project link and the model + content you wish to migrate and we can help you create a script for its migration.

I need an actual clone of the data and all the idā€™sā€¦if I write it manually it wonā€™t maintain the ids and will be different. It seems like there should be an easier way to just transfer a model and itā€™s content to another branch. Iā€™ll play with it though.

@jterry i donā€™t mean manually type in the IDs of records, just the logic:
You can use this call to get all records dynamically without having to hardcode any IDs: List all records - Record - Content Management API
And this call to the create new records based on the fetched information:
Create a new record - Record - Content Management API