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

'🛑 Could not load configuration' Error when attempting to change a Model Primary Key or Index Keys #3139

Open
2 tasks done
francotechadmin opened this issue Feb 1, 2025 · 2 comments
Assignees
Labels
api-graphql pending-community-response Issue is pending a response from the author or community. pending-triage question Further information is requested transferred

Comments

@francotechadmin
Copy link

francotechadmin commented Feb 1, 2025

How did you install the Amplify CLI?

NPM

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

v21.1.0

Amplify CLI Version

12.14.2

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 made

Describe the bug

The amplify CLI raises an non-descriptive error when attempting to update an existing Model with a new primary key or adding a new index key.
I updated the 'Todo' model in the below schema with a '@PrimaryKey ' on 'userID'
I ran 'amplify push --allow-destructive-graphql-schema-updates -y'
The error reads '🛑 Could not load configuration'.

# Starting Schema

type Todo @model @auth(rules: [{ allow: owner }]) {
  id: ID!
  content: String!
  isCompleted: Boolean!
  createdAt: AWSDateTime!
  updatedAt: AWSDateTime!
  userID: ID! 
}

type User
  @model
  @auth(
    rules: [
      { allow: owner, operations: [create, read] }
      { allow: public, provider: iam, operations: [read, update] }
    ]
  ) {
  id: ID!
  subscriptionStatus: String! # active, inactive, or null
  todos: [Todo] @hasMany(fields: ["id"]) # A user can have many todos
}
input UpdateUserSubscriptionInput {
  id: ID!
  subscriptionStatus: String!
}

type Mutation {
  createCheckoutSession(input: CreateCheckoutSessionInput!): CheckoutSession
    @function(name: "createCheckoutSession-${env}")
  generateAiTodos(input: GenerateAiTodosInput!): GeneratedTasksPayload
    @function(name: "generateAiTodos-${env}")
    @auth(rules: [{ allow: private }])
  batchCreateTodos(input: BatchCreateInput!): [Todo]
    @function(name: "generalTodoResolver-${env}")
    @auth(rules: [{ allow: private }])
  # no input or output required
  clearTodos: [Todo]
    @function(name: "generalTodoResolver-${env}")
    @auth(rules: [{ allow: private }])
}

input CreateCheckoutSessionInput {
  planId: String!
  userId: String!
  email: String!
}

type CheckoutSession {
  id: String!
}

input GenerateAiTodosInput {
  userId: ID!
  prompt: String!
}

# Returns array of strings
type GeneratedTasksPayload {
  tasks: [String]
}

input BatchCreateInput {
  todos: [CreateTodoInput!]!
}

input CreateTodoInput {
  content: String!
  isCompleted: Boolean!
  userID: ID!
}

Expected behavior

I expected the datasource to be deleted

Reproduction steps

I expected the DynamoDB table datasource to be reconstructed with userID! as a primary key.

Project Identifier

No response

Log output

# Put your logs below this line
🛑 Could not load configuration

Additional information

Workaround:

  1. Remove any resources with access to the model. For example, I had one function with access to the model. I had to remove its access by running 'amplify update function.
  2. Comment out the model. I commented out the 'Todo' model and any reference to it from the schema.
  3. Delete the datasource by running 'amplify push --allow-destructive-graphql-schema-updates -y'
  4. Uncomment the model and any references to it
  5. Update the model schema to desired state
  6. Run 'amplify push' to rebuild the resources
  7. Update any resources to restore previous access by running 'amplify update function.

Before submitting, please confirm:

  • 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.
@ykethan
Copy link
Member

ykethan commented Feb 3, 2025

Hey,👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂

@ykethan ykethan transferred this issue from aws-amplify/amplify-cli Feb 3, 2025
@AnilMaktala AnilMaktala self-assigned this Feb 4, 2025
@AnilMaktala AnilMaktala added the question Further information is requested label Feb 4, 2025
@AnilMaktala
Copy link
Member

Hi @francotechadmin, Thanks for bringing this up. Unfortunately, updating the primary key is not supported. If you need to change the primary key to a new field, you'll have to delete the existing table and recreate it. Please refer to this section of the documentation for more details. https://docs.amplify.aws/gen1/react/build-a-backend/graphqlapi/data-modeling/#configure-a-primary-key

Image

@AnilMaktala AnilMaktala added the pending-community-response Issue is pending a response from the author or community. label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-graphql pending-community-response Issue is pending a response from the author or community. pending-triage question Further information is requested transferred
Projects
None yet
Development

No branches or pull requests

3 participants