Cloning a Strapi project to another machine

System Information
  • Strapi Version: 4.0.7
  • Operating System: Win10
  • Database: PostgreSQL

So I spent weeks on moving my project from MongoDB to PostgreSQL and adding new features to it. I merged it from the working branch to my dev branch. Now I need to clone the project to another machine (my laptop). So on my PC I first exported my PG DB:

pg_dump my_db > my_db.sql

On my laptop I have a fresh install of PG. I created a DB with the same name. Then I imported that db:

psql my_db < my_db.sql

Then in my project I switched to dev branch and pulled it. I deleted the directories build, .cache, node_modules and the package-lock.json file. I installed all the dependencies and then rebuilt the project. So far everything went well. But when I tried to run npm run develop, I encountered the following errors:

Error: Unknown target api::icon.icon
    at createJoinTable (C:\work\Web\my_proj\backend\node_modules\@strapi\database\lib\metadata\relations.js:393:11)
    at createOneToOne (C:\work\Web\my_proj\backend\node_modules\@strapi\database\lib\metadata\relations.js:40:7)
    at createRelation (C:\work\Web\my_proj\backend\node_modules\@strapi\database\lib\metadata\relations.js:329:14)
    at createMetadata (C:\work\Web\my_proj\backend\node_modules\@strapi\database\lib\metadata\index.js:60:11)
    at new Database (C:\work\Web\my_proj\backend\node_modules\@strapi\database\lib\index.js:28:21)
    at Function.Database.init (C:\work\Web\my_proj\backend\node_modules\@strapi\database\lib\index.js:84:33)
    at Strapi.bootstrap (C:\work\Web\my_proj\backend\node_modules\@strapi\strapi\lib\Strapi.js:345:30)
    at Strapi.load (C:\work\Web\my_proj\backend\node_modules\@strapi\strapi\lib\Strapi.js:408:16)
    at async Strapi.start (C:\work\Web\my_proj\backend\node_modules\@strapi\strapi\lib\Strapi.js:161:9)
[2022-03-15 11:07:44.522] debug: ⛔️ Server wasn't able to start properly.

[2022-03-15 11:07:44.525] error: Error on attribute icon in model gear(api::gear.gear): Unknown target api::icon.icon
Error: Error on attribute icon in model gear(api::gear.gear): Unknown target api::icon.icon
    at createMetadata (C:\work\Web\my_proj\backend\node_modules\@strapi\database\lib\metadata\index.js:67:15)
    at new Database (C:\work\Web\my_proj\backend\node_modules\@strapi\database\lib\index.js:28:21)
    at Function.Database.init (C:\work\Web\my_proj\backend\node_modules\@strapi\database\lib\index.js:84:33)
    at Strapi.bootstrap (C:\work\Web\my_proj\backend\node_modules\@strapi\strapi\lib\Strapi.js:345:30)
    at Strapi.load (C:\work\Web\my_proj\backend\node_modules\@strapi\strapi\lib\Strapi.js:408:16)
    at async Strapi.start (C:\work\Web\my_proj\backend\node_modules\@strapi\strapi\lib\Strapi.js:161:9)

I tried to completely remove the directory, cloned the project again, installed, built and ran into the same result.
Tried to upgrade node version to 14.18.3, to be on the same node version as on my PC, rebuilt - same result.

What am I doing wrong? Why is this error happening? Is there any other way to migrate a project to another machine?

OK, I finally found out what was causing this problem. At the time, I used some .gitignore generator, and for MacOS it added something called Icon :blush:. And since I have an api called icon - it was ignored, despite capital/lowercase letters difference. Once removed, I was able to add that icon api to git, pushed it, pulled on my laptop, rebuilt and voila, everything finally worked!

2 Likes

I had the same problem. Thanks for sharing the solution!

No problem, glad I could help someone! :slight_smile: