Skip to content
\n

And then I try to insert it

\n
var dbTag = new DbTransactionTag\n{\n    TagId = tag.Id,\n    TransactionId = transaction.Id, // This is 100% not null, I've checked multiple scenarios with the debugger\n    UserId = UserId\n};\n\nawait supabase.From<DbTransactionTag>().Insert(dbTag, minimalQueryOptions, cancellationToken);
\n

But no matter what, I just get
\nSupabase.Postgrest.Exceptions.PostgrestException: {\"code\":\"23502\",\"details\":null,\"hint\":null,\"message\":\"null value in column \\\"transaction_id\\\" of relation \\\"transaction_tags\\\" violates not-null constraint\"}

\n

Am I missing something obvious here? I'm clearly setting the transaction_id field.

","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

I managed to solve it by changing PrimaryKey(\"\") to PrimaryKey(\"\", true). There's a hidden shouldInsert parameter there that should be true.

\n

So my class would be

\n
[Table(\"transaction_tags\")]\ninternal sealed class DbTransactionTag : BaseModel\n{\n-   [PrimaryKey(\"transaction_id\")]\n+   [PrimaryKey(\"transaction_id\", true)]\n    public Guid TransactionId { get; set; }\n-   [PrimaryKey(\"tag_id\")]\n+   [PrimaryKey(\"tag_id\", true)]\n    public Guid TagId { get; set; }\n    [Column(\"user_id\")]\n    public Guid UserId { get; set; }\n}
","upvoteCount":1,"url":"https://github.com/supabase-community/supabase-csharp/discussions/176#discussioncomment-11330511"}}}

Getting error 'null value in column' even though I set a value in the field #176

Closed Answered by Hertzole
Hertzole asked this question in Q&A
Discussion options

You must be logged in to vote

I managed to solve it by changing PrimaryKey("") to PrimaryKey("", true). There's a hidden shouldInsert parameter there that should be true.

So my class would be

[Table("transaction_tags")]
internal sealed class DbTransactionTag : BaseModel
{
-   [PrimaryKey("transaction_id")]
+   [PrimaryKey("transaction_id", true)]
    public Guid TransactionId { get; set; }
-   [PrimaryKey("tag_id")]
+   [PrimaryKey("tag_id", true)]
    public Guid TagId { get; set; }
    [Column("user_id")]
    public Guid UserId { get; set; }
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Hertzole
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant