Running an auto-generated migration fails with an invalid API key error

Describe the issue:

We have a dato primary branch called production from which we created a new development branch and built out a new design update. In the interim, we had to make quite a few data updates to our production branch which weren’t applied to the development branch so we couldn’t directly promote the development branch to primary as we would incur a loss of data.

The plan at this point was to create a new environment that was forked from production called prod-design-v2. We then ran the following command to autogenerate migrations that would get prod-design-v2 in-line with the schema updates that were done on the development branch.

npx datocms migrations:new designUpdate --autogenerate=development:prod-design-v2 --api-token=api_token --profile project_name

The command above ran successfully and generated the migrations.

Our next step was to apply those migrations to prod-design-v2 with the following command

npx datocms migrations:run --source=prod-design-v2 --in-place --api-token=api_token --profile project_name

Running that command returned the following error but we are unsure of how to resolve the issue. We double checked that we are using the Full access API token and we generated a new token as well with admin privileges but that didn’t change the error.

Hey @jude,

The “API key” is actually referring to the model ID here, e.g. post or page or similar, not your project API tokens.

We are currently debugging some potentially related bugs in the migration script generator failing when projects are edited after forking and causing model name conflicts:

At first glance, your issue MAY be similar. We are testing an alpha fix internally, but it’s not quite ready for release yet.

We can see if that might also fix your issue… but to do so, could you please send us (here or at support@datocms.com if you prefer) your project URL and the generated migration script so we can take a more detailed look? With your permission, I’d like to try the fix on a copy/fork of your prod-design-v2 environment to see if it works? (We’d create a new one, like prod-design-v2-datocms-support-test and run the alpha fix there.)

Or if you’d rather wait for a fully tested fix, that’s OK too. We’ll let you know once we finish the investigation and produce an update then.

Sorry about that, and thanks for your patience! We’ll provide an update as soon as we can.

1 Like

Hey @roger thanks for the response.

We ended up making the changes manually for the time being as we were in a bit of a rush. I’m happy to wait for the fix to go live so we can try it post that. Is there a rough ETA on when that would be closer to a release?