Update Missing Reference UIDs for Entries, Assets, and Extensions
When importing data via Contentstack's CLI, if some of the reference UIDs of assets, entries, or extensions in the destination stack are not updated within the entries. This can result in those entries not displaying correctly, potentially affecting functionalities that depend on them.
To resolve this, you can use the script 05-Update-reference-entry-from-mapper to update the references. This script can be used under the following conditions:
- The referenced entries, assets, and extensions have already been created in the stack.
- The unique identifiers (UIDs) of the referenced items have not been updated in the referring entries.
This step-by-step guide lets you update the missing reference UIDs of entries, assets, and extensions in CLI.
Prerequisites
- Contentstack account
- CLI installed and configured (version 1.17.4 and above)
- CLI authenticated
Steps for Execution
Follow the steps below to update the missing reference UIDs:
- Import the data from the source stack using the cm:stacks:import command.
- Download the examples folder and navigate to the folder using the cd command in the terminal.
cd <path-to-examples>
- Create a config.json file containing the following key-value pairs:
- mapper-path: The path to the backup directory where the logs are stored.
You can find the following path after a successful import operation in your CLI:
<path>/_backup_<number>/logs/import
Copy and use <path>/_backup_<number> in the config file. - contentTypes: An array of content type UIDs whose references need to be updated.
{ "mapper-path": "<path>/_backup_<number>/", "contentTypes": [ "ct1", "ct2", .... ] }
- mapper-path: The path to the backup directory where the logs are stored.
- Find the 05-Update-reference-entry-from-mapper script in the examples folder. Execute the script using the Migration command as follows:
csdx cm:stacks:migration --file-path ./05-Update-reference-entry-from-mapper.js --config-file ./config.json -k <stack_ApiKey>
Troubleshoot
If you are facing a Migration Unsuccessful or Module cannot be found error, please try one of the following troubleshooting methods:
- Troubleshoot in your current terminal session:
- Windows (CMD):
FOR /F "usebackq tokens=*" %i IN (`npm root -g @contentstack/cli`) DO SET NODE_PATH=%i/@contentstack/cli/node_modules
- Windows (PowerShell):
foreach ($i in $(npm root -g @contentstack/cli)) { $env:NODE_PATH = "$i/@contentstack/cli/node_modules" }
- Mac/Unix:
export NODE_PATH="$(npm root -g @contentstack/cli)/@contentstack/cli/node_modules"
- Windows (CMD):