【问题标题】:AWS Amplify API: Can't remove @key from a @modelAWS Amplify API:无法从 @model 中删除 @key
【发布时间】:2020-10-12 06:24:36
【问题描述】:

使用 AWS Amplify,我终于删除了我的一个模型的 @key 属性(我不需要它,我想要一个自动生成的 UUID)。

执行amplify push 时出现此错误

Attempting to edit the key schema of the NewsTable table in the News stack. 
An error occured during the push operation: Attempting to edit the key schema of the NewsTable table in the News stack.

我该如何强制? 我不介意丢失数据,因为它不在生产中。我只是不想用糟糕的重命名来破解它,也不想为此删除我的整个 App Sync 项目。

【问题讨论】:

  • 我发现的快速破解:我添加了一个虚拟@model,并从 schema.graphql 中完全删除了我的 News 模型。我推了它,它起作用了。然后我放回我的新闻模型并移除我的虚拟模型(没有钥匙)。它奏效了。但这是真正的方法吗?
  • 我采用了完全相同的方法。我不同意。我观察到,当先前环境中的数据绝对是一次性的时,我始终可以使用 amplify cli 创建具有修改模式的单个新环境,并删除现有的先前环境。 amplify push 限制来自 DynamoDB,因为 GSI 是在创建 DynamoDB 表时创建的。与表迁移相比,新环境的工作量肯定更少。
  • 虚拟模型是什么意思?只是为了推动它?如果是这样,为什么需要它来删除密钥?举个例子就好了。
  • 我会添加一个更详细的答案@PeteDuncanson

标签: amazon-web-services aws-amplify aws-appsync


【解决方案1】:

不用于生产。请注意,此方法会清除您的所有数据。

假设您需要从“汽车”模型中删除密钥“licenceNumber”

type Car @model {
  licenceNumber: String! @key
  color: String!
}

推送任何内容,但删除该汽车模型

type Car_renamed_to_make_the_push_work @model {
  licenceNumber: String!
  color: String!
}

然后再次重命名您的模型,但没有密钥

type Car @model {
  licenceNumber: String!
  color: String!
}

【讨论】:

  • 哇哦,真的就是这样!有趣的工作,非常感谢@maxime 花时间回来充实它。
猜你喜欢
  • 2021-11-16
  • 2022-06-10
  • 1970-01-01
  • 2021-08-23
  • 1970-01-01
  • 2019-08-30
  • 2020-06-13
  • 2022-08-24
  • 2022-07-12
相关资源
最近更新 更多