Restore of strapi configuration with strapi config:restore command fails

I am new to Strapi and am very pleased with its features. I have created several collection types with the content builder and now I want to export these types to another Strapi server. I learned from the documentation that this can be done with the config:dump and config:restore CLI commands. I have successfully created a dump.json file but when I try to restore this dump.json on my other Strapi server (via cli command: npm run strapi config:restore --file dump.json -s replace), the following stack trace is thrown at me:

[2020-10-20T14:09:20.368Z] error Bootstrap function in admin failed
[2020-10-20T14:09:20.371Z] error TypeError: Cannot read property ‘primaryKey’ of undefined
at Object.getNonVisibleAttributes (D:\node\newproject\node_modules\strapi-utils\lib\content-types.js:48:24)
at getNestedFieldsWithIntermediate (D:\node\newproject\node_modules\strapi-admin\services\content-type.js:87:51)
at D:\node\newproject\node_modules\strapi-admin\services\content-type.js:98:29
at D:\node\newproject\node_modules\strapi-admin\node_modules\lodash\lodash.js:914:11
at D:\node\newproject\node_modules\strapi-admin\node_modules\lodash\lodash.js:4925:15
at baseForOwn (D:\node\newproject\node_modules\strapi-admin\node_modules\lodash\lodash.js:2990:24)
at D:\node\newproject\node_modules\strapi-admin\node_modules\lodash\lodash.js:4894:18
at baseReduce (D:\node\newproject\node_modules\strapi-admin\node_modules\lodash\lodash.js:911:5)
at Function.reduce (D:\node\newproject\node_modules\strapi-admin\node_modules\lodash\lodash.js:9707:14)
at getNestedFieldsWithIntermediate (D:\node\newproject\node_modules\strapi-admin\services\content-type.js:89:12)
at Array. (D:\node\newproject\node_modules\strapi-admin\services\content-type.js:162:28)
at Array.map ()
at Object.cleanPermissionFields (D:\node\newproject\node_modules\strapi-admin\services\content-type.js:150:15)
at Object.cleanPermissionInDatabase (D:\node\newproject\node_modules\strapi-admin\services\permission.js:179:78)
at async module.exports (D:\node\newproject\node_modules\strapi-admin\config\functions\bootstrap.js:19:3)
at async Strapi.load (D:\node\newproject\node_modules\strapi\lib\Strapi.js:336:5)

I am using Strapi 3.2.4 on Windows server with NodeJS v14.13.1. How can I get this to work?

Hello!

The strapi config:dump and strapi config:restore only apply to the core_store table in the database, the actual model settings are stored in the ./api/*/models/*.settings.json so you should be able to just copy the model settings over to the new project (or even just the model folder)

So something like cp -R api/somemodel /path/to/your/new/project/api/

2 Likes

Thanks for the tip to also copy the models to the api folder structure. Now it works for plain collection types that do not include components. I do however have one collection that refers to a (repeatable) component. When I copy the model of this collection to the api folder, the server restarts but fails with the primary key issue as shown in the above stacktrace. If I physically look in the sqlite database, I can see in the core_store table of the target environment that content type configuration entries (plugin_content_manager_configuration_content_types) have been restored by the strapi config:restore command but component entries (plugin_content_manager_configuration_components) are not getting restored. Could it be the case that the config:dump & restore commands only support migration of collection types and do not yet support the migration of components?

1 Like

Components are also file based, you can copy the components folder at the root of the project over as well.

As I mentioned the config:dump/restore does not do any model migration, on a single table in the database called the core_store which holds some general plugin configuration. Everything else is file based.

Many thanks! After copying the component files, everything works in the target environment.

1 Like