Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't edit/remove @primaryKey field w/ amplify push --allow-destructive-graphql-schema-updates when @hasMany field declared #99

Open
5 tasks done
brentcappello opened this issue Feb 28, 2022 · 6 comments

Comments

@brentcappello
Copy link

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

16.13.0

Amplify CLI Version

7.6.22

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No manual changes

Amplify Categories

api

Amplify Commands

push

Describe the bug

I received an error while trying to amplify push --allow-destructive-graphql-schema-updates

✖ An error occurred when pushing the resources to the cloud
🛑 An error occurred during the push operation: ["Index: 0 State: {"deploy":"waitingForDeployment"} Message: Resource is not in the state stackUpdateComplete"]
⚠️ Please refer Amplify CLI troubleshooting guide at : https://docs.amplify.aws/cli/project/troubleshooting/

I could not modify or remove the field @primaryKey while I had another field using @hasMany
In the example below I couldn't remove the @primaryKey on the username field without getting the error.

type Listing
  @model
  @auth(
    rules: [
      { allow: owner, ownerField: "username" }
      { allow: public, operations: [read] }
    ]
  ) {
  id: ID!
  username: String! @primaryKey
  about: String
  image: S3Object
  reviews: [Review] @hasMany
}

I was able to workaround the error and get a proper deployment with this sequence:

  1. Remove field using @hasMany
  2. amplify push
  3. Remove @primaryKey from field
  4. amplify push --allow-destructive-graphql-schema-updates
  5. Replace field with @hasMany
  6. amplify push

Expected behavior

Expected to see amplify push --allow-destructive-graphql-schema-updates command succeed.

Or perhaps a more detailed error message stating I cannot modify/remove an existing PK while using a relationship.

Reproduction steps

  1. Remove @primaryKey
  2. Push with amplify push --allow-destructive-graphql-schema-updates

Make sure you have a field with @hasMany declared and a reciprocating Model and field with @belongsTo

GraphQL schema(s)

type Listing
  @model
  @auth(
    rules: [
      { allow: owner, ownerField: "username" }
      { allow: public, operations: [read] }
    ]
  ) {
  id: ID!
  username: String! @primaryKey
  about: String
  image: S3Object
  reviews: [Review] @hasMany
}

Log output

# Put your logs below this line


Additional information

I was able to workaround the error and get a proper deployment with this sequence:

  1. Remove field using @hasMany
  2. amplify push
  3. Remove @primaryKey from field
  4. amplify push --allow-destructive-graphql-schema-updates
  5. Replace field with @hasMany
  6. amplify push
@sachscode
Copy link
Contributor

Hi
I was not able to reproduce this issue . I created a schema with 3 models ( Blog=hasmany=>Post=hasMany=>Comment ) with PK in Blog as userName. I removed hasMany and pushed and followed it up with removed PK and push). All the amplify push went thought successfully.
Questions to root-cause further:

  1. Could you please share the entire GraphQL schema before removing hasMany and after removing hasMany. Specifically can you share the changes made to the Review model.
  2. Could you please confirm the current state of your cloudformation stack ?

@jnastaskin
Copy link

@sachscode I'm having a similar issue. For me, I have a model that has a @manytomany connection that has been pushed. Then, I update that models primary key to a new field and I get the error.

Have you tried that sequence of events?

@josefaidt josefaidt added the p2 label Apr 7, 2022
@alharris-at alharris-at transferred this issue from aws-amplify/amplify-cli May 17, 2022
@jemucino
Copy link

jemucino commented Jul 4, 2022

I have been having the same issue for the last couple of days, though I haven't confirmed if it is in fact caused by the presence of the @hasmany directive in my model. I will try to manually remove the @hasmany relationship first and will report back with the results.

This is issue is causing a huge slow down during active development while evolving my schema. Is there a way to just tell amplify during the push operation to forget about all existing resources and rebuild the api or the entire environment from scratch? It seems that --allow-destructive-graphql-schema-updates is a less destructive method, but if I don't really care about any data in my test environment having a nuclear option would be a good enough workaround for now.

@jemucino
Copy link

jemucino commented Jul 5, 2022

I got rid of all the @hasmany relationships in my model and I was still unable to change @PrimaryKey. Got the same error message about the failed deployment. I also got rid of all @Index directives and still no joy. At this point the only thin that worked was commenting out the model and all relationships to it from other tables, then doing a push, followed by re-adding the model with the new @PrimaryKey, then doing another push. Maybe it had something to do with my @auth directive being dependent on the field that I wanted to use for the new @PrimaryKey? But I don't have time to test every possiblity today.

@tiyberius
Copy link

Thank you @brentcappello for the six step workaround you provided in your question, it saved my life today. I was absolutely furious at Amplify, but the steps you described worked flawlessly. Thank you!!

@malmgrens4
Copy link

malmgrens4 commented Jun 3, 2023

Ran into this issue with no @hasmany relationships. Running into this when trying to mark a field that isn't "id" as the primary key. My suspicion is if the table isn't initially created with a field other than id being used it will fail when you try to mark any other ones with @PrimaryKey in subsequent updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants