代码之家  ›  专栏  ›  技术社区  ›  CCCC

strapi-如何使用迁移脚本创建集合类型

  •  0
  • CCCC  · 技术社区  · 3 年前

    背景
    我用创建了我的第一个strapi项目 npx create-strapi-app@latest my-project --quickstart 。

    我可以访问管理控制台 enter image description here

    意图
    正如你所看到的,只有 User 集合类型,我想做的是创建一个迁移脚本来创建另一个集合类型。 原因是我希望有一个单一的真相来源,所以我不想直接在管理控制台中创建集合类型

    我尝试过的
    我试着询问了chatGPT,它为我提供了以下解决方法- npm run create-content-type 。

      "dependencies": {
        "@strapi/strapi": "4.11.1",
        "@strapi/plugin-users-permissions": "4.11.1",
        "@strapi/plugin-i18n": "4.11.1",
        "better-sqlite3": "8.0.1"
      },
      "scripts": {
        "develop": "strapi develop",
        "start": "strapi start",
        "build": "strapi build",
        "strapi": "strapi",
        "create-content-type": "strapi generate:migration create_my_collection_type"
      },
    

    错误显示

    error: unknown command 'generate:migration'
    

    我也试过 strapi make:migration create_my_collection_type ,但效果不太好。我还查看了官方文件,找不到任何有用的资源。

    在我的情况下可以这样做吗?

    0 回复  |  直到 3 年前
        1
  •  0
  •   kulturman    3 年前

    你可以使用 strapi generate ,系统将提示您选择要生成的内容,只需选择 content-type 。如果您没有strapi本地添加脚本 "strapi:generate": "strapi generate"