You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS Amplify GraphQL Schema执行amplify push报错无法定位问题

第一步:先获取详细报错信息

执行带debug参数的推送命令可以看到完整错误日志:

amplify push --debug

也可以登录AWS控制台进入CloudFormation服务,找到对应Amplify环境的CloudFormation栈,查看栈事件中的失败详情,能定位到具体是哪个资源创建出错。

你当前Schema存在的明确错误

  • Article模型关联字段配置错误:Article下的tagArtCons字段的@connection中填的fields: ["articleId"]不存在,Article模型没有articleId字段,此处应该用Article自身的主键id关联TagArtCon中的articleId字段,修改为fields: ["id"]
  • Tag模型关联字段配置错误:Tag下的tagArtConns字段的@connection中填的fields: ["tagId"]不存在,Tag模型没有tagId字段,此处应该用Tag自身的主键id关联TagArtCon中的tagId字段,修改为fields: ["id"]
  • GSI分区键非必填错误:Tag模型的byFrontPage自定义索引将可选字段frontpage作为分区键,DynamoDB的全局二级索引分区键必须为必填字段,要么给frontpage加上!改为必填类型,要么调整索引的分区键为其他必填字段
  • 关联字段放置位置错误:parentRelations和childRelations是标签之间的父子关系关联,不应该放在文章标签关联表TagArtCon中,应该移动到Tag模型下,符合你设计的标签父子关系的业务逻辑

修改后可用的Schema示例

type Article
  @model
  @key(name: "bySource", fields: ["sourceId", "dateWritten"]) {
  id: ID!
  link: AWSURL!
  title: String!
  dateWritten: String!
  createdAt: String!
  data: AWSJSON!
  approved: Boolean!
  admin: Boolean!
  creatorId: ID!
  creator: User @connection(fields: ["creatorId"])
  sourceId: ID!
  source: Source @connection(fields: ["sourceId"])
  tagArtCons: [TagArtCon]
    @connection(keyName: "byArticle", fields: ["id"])
}

type Tag @model @key(name: "byFrontPage", fields: ["frontpage"]) {
  id: ID!
  name: String!
  createdAt: String!
  creatorId: ID!
  data: AWSJSON!
  frontpage: String! # 改为必填,满足GSI分区键要求,不需要可删除该索引
  official: Boolean!
  tagArtConns: [TagArtCon] @connection(keyName: "byTag", fields: ["id"])
  parentRelations: [TagRelation]
    @connection(keyName: "byParent", fields: ["id"])
  childRelations: [TagRelation]
    @connection(keyName: "byChild", fields: ["id"])
}

type TagArtCon
  @model
  @key(name: "byTag", fields: ["tagId"])
  @key(name: "byArticle", fields: ["articleId"]) {
  id: ID!
  tagId: ID!
  articleId: ID!
  creatorId: ID!
  createdAt: String!
  article: Article @connection(fields: ["articleId"])
  tag: Tag @connection(fields: ["tagId"])
}

type TagRelation
  @model
  @key(name: "byParent", fields: ["parentId"])
  @key(name: "byChild", fields: ["childId"]) {
  id: ID!
  parentId: ID!
  childId: ID!
  creatorId: ID!
  createdAt: String!
  parentTag: Tag @connection(fields: ["parentId"])
  childTag: Tag @connection(fields: ["childId"])
}

type Source @model {
  id: ID!
  sourceName: String!
  sourceUrl: String!
  sourceImage: String!
  creatorId: ID!
  articles: [Article] @connection(keyName: "bySource", fields: ["id"])
}

type User @model {
  id: ID!
  userName: String!
  userImage: String!
  admin: Boolean!
  createdAt: String!
  data: AWSJSON
}

内容的提问来源于stack exchange,提问作者Joshua Foxworth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 07:06:04