supabase / postgrest-dart

Dart client for PostgREST
https://supabase.com
MIT License
136 stars 38 forks source link

Lest the table name begins with an uppercase, an error is thrown when data is inserted: "message: null value in column "id" not-null constraint" #22

Closed Hu-Wentao closed 3 years ago

Hu-Wentao commented 3 years ago

Bug report

Lest the table name begins with an uppercase, an error is thrown when data is inserted: "message: null value in column "id" not-null constraint"

Describe the bug

Table names can only be used properly if they begin with a lowercase letter

To Reproduce

  1. Create a table and name it Test
  2. Add id and foo fields and set them to int4
  3. Call postgrest - dart
    // ...
    from ("Test ").Insert({"foo",3}).execute();
phamhieu commented 3 years ago

~Related to this https://github.com/supabase/supabase/issues/859~ ~Maybe postgrest-dart doesn't add double quote to table, column with uppercase chars.~

postgrest can handle uppercase table name and column name. It' not a problem with uppercase char.

phamhieu commented 3 years ago

from ("Test ").Insert({"foo",3}).execute();

your insert object is wrong. it should be postgrest.from('Test').insert({'id':3, 'foo':"hello-world"}).execute();

Hu-Wentao commented 3 years ago

from ("Test ").Insert({"foo",3}).execute();

your insert object is wrong. it should be postgrest.from('Test').insert({'id':3, 'foo':"hello-world"}).execute();

What I mean by that is to use a self-incrementing primary key.

When I was using Supabase, I found that the primary key was automatically generated only by changing the table name to lowercase, and if the table name was uppercase, it would be an error

phamhieu commented 3 years ago

Hi @Hu-Wentao, I add unit-test for insert/delete/select with uppercase table name. They works properly https://github.com/supabase/postgrest-dart/commit/954c10c19140c3beab0cb800bcd0461f7335c3b6

can you try again on your side and let me know the result. Thanks

Hu-Wentao commented 3 years ago

Sorry that I did not check issues in time, because I later used SpringBoot to build backend.

I just re-tested it with the old code, and it didn't throw any exceptions.

Thank you all for your great work anyway!