'Amplify Flutter : Error SQLiteLog( 5594) : (1) duplicate column name when using Graphql BelongsTo relationship

I am modelling a very simple schema in Flutter using Amplify GraphQL Api where there are Posts including several Comments. But a user can put only one comment per post. So my models was at first:

type Comment @model {
  id: ID!
  …
  post: Post @hasOne
}

type Post @model {
  id: ID!
  …
  comments: [Comment] @hasMany
}

It worked fine, but it happens that I need to know, when the app user lists Posts,if he had already put a comment on one of them (dipending on that comment button appear or not). I would like to query all posts where my user did not already added a comment. Following API specification https://docs.amplify.aws/cli/graphql/data-modeling/#configure-a-secondary-index I changed @hasOne relationship in @belongsTo relationship, in order to make relationship bi-directionnal. Fields argument are optional.

type Comment @model {
  id: ID!
  …
  post: Post @belongsTo
}

Once pushed on Amplify, it’s impossible to start Amplify when running my app. I noticed this error :

I/amplify:aws-datastore( 5594): Creating table: Post
I/amplify:aws-datastore( 5594): Creating table: Comment
E/SQLiteLog(5594): (1) duplicate column name: postCommentId

I can’t find this column name, I guess it’s created automatically. I tried to use fields belongsTo parameter (fields: ["postID"]) , but the error the same : column name is just replaced by postID. Rolling back from @belongsTo to @hasOne solves duplicate error. I’m using :

amplify_flutter: ^0.3.0-0
amplify_api: ^0.3.0-rc.3

What am I missing ? Any help or idea to solve my problem is appreciated. Thank you !



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source