首页 > 解决方案 > AWS Amplify API:无法从 @model 中删除 @key

问题描述

使用 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 项目。

标签: amazon-web-servicesaws-amplifyaws-appsync

解决方案


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

假设您需要从“Car”模型中删除密钥“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!
}

推荐阅读