defaultFn when using magic sql is not applying
When using "magic sql" and Inserting a row, the id isn't generated automatically. It only seem to work for me when calling the default Function manually
Is this an intended behaviour or am i missing something?
7 Replies
not sure what sql flavor you are using but at least for postgres, you have to explicitly list the columns you are inserting into if you want to skip some and have it filled by default: "The target column names can be listed in any order. If no list of column names is given at all, the default is all the columns of the table in their declared order; or the first N column names, if there are only N columns supplied by the VALUES clause or query. The values supplied by the VALUES clause or query are associated with the explicit or implicit column list left-to-right."
I am using postgres.
The query:
fails because it violates the not null constraint of id. That why i think the default function isnt working when using magic sql
Its also working when using the normal query builder
oh, do you not have a default defined at the sql level
that would be why
check your table DDL to see if you have a default defined
That part of the drizzle schema is doing exactly this right? For other inserting ways its also working. Only Magic SQL seems to not work
Because your dB has no idea what that function is. Try or if you have uuid-ossp extension installed
oh makes sense. So
$defaultFn
seems to be useless in that case
thanks for your helpinside a magic SQL yes, since its jsut sending whats there to the db, but on your defintition you could have
and then it wouldnt matter