Closed Phantom-KNA closed 1 year ago
@Phantom-KNA could you show the code for your model and the call you're attempting with postgrest?
@Phantom-KNA I would assume that it is an issue with your Model not being defined correctly.
Assuming your model is Favorites
[Table("favorites")]
public class Favorite: BaseModel
{
[PrimaryKey("id")] // <-- Should be defined in Supabase Dashboard/Postgres to autogenerate this id
public string Id { get; set; }
[Column("reference_id")]
public string ReferenceId { get; set; }
[Column("is_favored")]
public bool IsFavored { get; set; }
}
This will let you insert a model and ignore the Id
field. If you're trying to generate the Id
client side (not recommended) then change the model so that PrimaryKey("id", true)
Thanks a lot, I'll try this. Thank you!!!!
How did you assume that my model was a favorite??, nobody had that information??
In your error log:
Unhandled exception. Postgrest.RequestException: null value in column "id" of relation "favorites" violates not-null constraint
@Phantom-KNA I would assume that it is an issue with your Model not being defined correctly.
Assuming your model is
Favorites
[Table("favorites")] public class Favorite: BaseModel { [PrimaryKey("id")] // <-- Should be defined in Supabase Dashboard/Postgres to autogenerate this id public string Id { get; set; } [Column("reference_id")] public string ReferenceId { get; set; } [Column("is_favored")] public bool IsFavored { get; set; } }
This will let you insert a model and ignore the
Id
field. If you're trying to generate theId
client side (not recommended) then change the model so thatPrimaryKey("id", true)
Why is it not recommended to generate this id, I mean, I am saving a string list and in the ID I am trying to save with the user ID that is obtained in this way:
supabase.Auth.CurrentClient.Id
@Phantom-KNA I would assume that it is an issue with your Model not being defined correctly.
Assuming your model is
Favorites
[Table("favorites")] public class Favorite: BaseModel { [PrimaryKey("id")] // <-- Should be defined in Supabase Dashboard/Postgres to autogenerate this id public string Id { get; set; } [Column("reference_id")] public string ReferenceId { get; set; } [Column("is_favored")] public bool IsFavored { get; set; } }
This will let you insert a model and ignore the
Id
field. If you're trying to generate theId
client side (not recommended) then change the model so thatPrimaryKey("id", true)
Why is it not recommended to generate this id, I mean, I am saving a string list and in the ID I am trying to save with the user ID that is obtained in this way:
supabase.Auth.CurrentClient.Id
This is my model:
Table("favorites")]
public class Favorite: BaseModel
{
[PrimaryKey("id")]
public string Id { get; set; }
[Column("list_movie")]
public List<string> ListMovie { get; set; }
[Column("list_tv")]
public List<string> { get; set; }
}
For string listings in the table I use jsonb, which should i use for id string or uuid?
Why is it not recommended to generate this id, I mean, I am saving a string list and in the ID I am trying to save with the user ID that is obtained in this way: supabase.Auth.CurrentClient.Id
Ah sorry, that's my preference, not a hard rule. I generally believe that the database should handle ID generation for new records, not clients. You are free to do as you will!
For string listings in the table I use jsonb, which should i use for id string or uuid?
In the c# model, you'll probably want to use string
with that setup.
Why is it not recommended to generate this id, I mean, I am saving a string list and in the ID I am trying to save with the user ID that is obtained in this way: supabase.Auth.CurrentClient.Id
Ah sorry, that's my preference, not a hard rule. I generally believe that the database should handle ID generation for new records, not clients. You are free to do as you will!
For string listings in the table I use jsonb, which should i use for id string or uuid?
In the c# model, you'll probably want to use
string
with that setup.
Thanks bro, use C# Guid as model type, thanks for the time!!
Happy to help!
Bug report
About Insert Method
Describe the bug
Get a Exception when at use.
Error
Unhandled exception. Postgrest.RequestException: null value in column "id" of relation "favorites" violates not-null constraint at Postgrest.Helpers.MakeRequest(ClientOptions clientOptions, HttpMethod method, String url, JsonSerializerSettings serializerSettings, Object data, Dictionary(String[] args)
2 headers, CancellationToken cancellationToken) at Postgrest.Helpers.MakeRequest[T](ClientOptions clientOptions, HttpMethod method, String url, JsonSerializerSettings serializerSettings, Object data, Dictionary
2 headers, Func`1 getHeaders, CancellationToken cancellationToken) at SupabaseExample.Program.Main(String[] args) in D:\Development\Example\Supabase SRC\supabase-csharp-0.6.2\Examples\SupabaseExample\Program.cs:line 39 at SupabaseExample.Program.System information
Additional context
I try change the value, always is null.