PostgresError: null value in column "id" of relation "pairs" violates not-null constraint
Hello, I am fairly new to Drizzle and working with databases, so I am running into a problem that I am unsure how to solve and hope that you can help me with it.
I use Directus CMS to create all of my tables. Then, I wrote schema.ts (using introspect and making a couple of manual changes).
So, one of my tables looks like this:
Now whenever i try to insert new pair like this
I get the following error:
PostgresError: null value in column "id" of relation "pairs" violates not-null constraint
What confuses me is that in Directus, I have checked 'ON CREATE: Generate and Save UUID,' which is working just fine.
Please help me understand how I can get around this error.
10 Replies
After you make changes to the schema, you need to either generate and run the migration or use the push command, so that the dababase is aware of the schema changes you made locally
That makes sense. However, I think that changing the database like that would:
- Delete tables that I removed from the schema, which Directus uses internally.
- Potentially create a change in some table that Directus doesn't know how to deal with.
My idea was to use Directus to create tables, generate schema using introspect with drizzle-kit, cleanup the schema and then manually keep it in sync with database
Can you log the query to the console and pass it here?
Also this is what my database looks like
And directus schema
Well, I'm not familiar with directus, but you don't have a default defined at the database level.
This might be something directus is doing for you
You could change your schema to:
That should work with the setup that you have
Thanks! Yes its likely something that directus does on its level.
When i try to do it as you showed i get ts error:
What version of drizzle-orm are you running?
Updated it and it works now 🙂
at least ts , will see for default now
Everything works now. Thanks a lot !