Describe the bug
I have simple one to many relationship. I haven't even gotten to many part yet. I am just testing adding and deleting to one part of relationship. I can add but I cannot delete. I get this error
Failed to execute 'index' on 'IDBObjectStore': The specified index was not found
To Reproduce
npx create-react-app blog --use-npm --template typescript
amplify init
amplify add api not adding auth just trying to keep it simple.
add following schema
type Post @model {
id: ID!
title: String!
postComments: [Comment] @connection(keyName: "byPost", fields: ["id"])
}
type Comment @model
@key(name: "byPost", fields: ["postID"]) {
id: ID!
postID: ID!
content: String!
}
then I create post this part works.
But when I try to delete post then it errors out.
I haven't tried adding comments yet.
async function deletePost(id: string) {
try {
const original = await DataStore.query(Post, id)
console.log(original)
await DataStore.delete(original)
} catch (err) {
console.error(err)
}
}
I do get the original post but I just cannot delete it. I get following error
Failed to execute 'index' on 'IDBObjectStore': The specified index was not found
Thank you @apoorvmote
We are tracking this together with the cli team.
There's work already started: https://github.com/aws-amplify/amplify-cli/pull/3680
The new warning looks good 馃憤 @manueliglesias!
Is there a ticket to track support for keyName?
This is upsetting now I get following error.
Error: DataStore does not support connection directive with keyName
Why did it not warn me before I did amplify push.
Breaking changes like this should have some kind of warning on blog post or on cli or change log or anywhere.
Is there a ticket to track support for keyName?
I am also interested in the same
There should also be warning on datastore. Because everything is saved in datastore locally but when you push to cloud then lots of things start to break. Many things don't sync with API for whatever reason.
So I always push to cloud before testing the app. I cannot just start testing/developing app with datastore alone.
There are lots of thing that can go wrong when amplify push. So I used to generate amplify codegen models after push is successful. But I have to change that now.
@apoorvmote by chance we actually looked at this earlier today, and there are two issues at play. First the keyName is indeed not supported yet for DataStore. We're looking at designing something simpler there but it is on our radar. The check put in place was to avoid problems but unfortunately it was added in a newer CLI version which I think you've upgraded to. I'd suggest reverting and updating your schema.
However there might be a bug here as well which is the crux of the issue that you've reported. We should be able to cascade the deletes in a 1:N relationship but the IDBObjectStore is unexpected. We'll look into this to see if we can reproduce. In the meantime I'll transfer this to the JavaScript repo as that issue is on the library side.
Following up for future reference: We updated the docs for Relational modeling. We made some improvements to the CLI, the library on how it handles this internally, and tried to be explicit about schemas in the documentation including how to use @key.
Hello, I have also run into this problem, is there a solution to this, thank you.
Most helpful comment
@apoorvmote by chance we actually looked at this earlier today, and there are two issues at play. First the
keyNameis indeed not supported yet for DataStore. We're looking at designing something simpler there but it is on our radar. The check put in place was to avoid problems but unfortunately it was added in a newer CLI version which I think you've upgraded to. I'd suggest reverting and updating your schema.However there might be a bug here as well which is the crux of the issue that you've reported. We should be able to cascade the deletes in a 1:N relationship but the
IDBObjectStoreis unexpected. We'll look into this to see if we can reproduce. In the meantime I'll transfer this to the JavaScript repo as that issue is on the library side.