ansipedantic
ansipedantic
DTDrizzle Team
Created by ansipedantic on 12/21/2023 in #help
Migrations with new notNull() columns
ok.. sorry for the confusion @solo - but your answer also helped me figure it out.. so thank you!
10 replies
DTDrizzle Team
Created by ansipedantic on 12/21/2023 in #help
Migrations with new notNull() columns
so, i need to make sure to provide a .default(...) when adding a .notNull() to an existing table
10 replies
DTDrizzle Team
Created by ansipedantic on 12/21/2023 in #help
Migrations with new notNull() columns
but i just tried again and it worked 😮
10 replies
DTDrizzle Team
Created by ansipedantic on 12/21/2023 in #help
Migrations with new notNull() columns
oh hmm hang on.. I thought I had an issue w/ using .notNull().default('asdf') also throwing an error..
10 replies
DTDrizzle Team
Created by ansipedantic on 12/21/2023 in #help
Migrations with new notNull() columns
Hi @solo thanks for the reply. However, this is not the case I am trying to solve. I am adding a brand new column foo to an existing table.. I am not updating an existing column. So, Step 1 in your above message is the equivilent of what I am trying to do, and what is causing the error
10 replies
DTDrizzle Team
Created by ansipedantic on 12/21/2023 in #help
Migrations with new notNull() columns
this is the migration file:
ALTER TABLE "someTable" ADD COLUMN "foo" text NOT NULL;
ALTER TABLE "someTable" ADD COLUMN "foo" text NOT NULL;
and this is the error when I run the migrate(...) code
Query: select id, hash, created_at from "drizzle"."__drizzle_migrations" order by created_at desc limit 1
Query: ALTER TABLE "someTable" ADD COLUMN "foo" text NOT NULL;
PostgresError: column "foo" of relation "someTable" contains null values
at ErrorResponse (/workspaces/bugrules/node_modules/postgres/cjs/src/connection.js:771:26)
at handle (/workspaces/bugrules/node_modules/postgres/cjs/src/connection.js:473:6)
at Socket.data (/workspaces/bugrules/node_modules/postgres/cjs/src/connection.js:314:9)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Socket.Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
Query: select id, hash, created_at from "drizzle"."__drizzle_migrations" order by created_at desc limit 1
Query: ALTER TABLE "someTable" ADD COLUMN "foo" text NOT NULL;
PostgresError: column "foo" of relation "someTable" contains null values
at ErrorResponse (/workspaces/bugrules/node_modules/postgres/cjs/src/connection.js:771:26)
at handle (/workspaces/bugrules/node_modules/postgres/cjs/src/connection.js:473:6)
at Socket.data (/workspaces/bugrules/node_modules/postgres/cjs/src/connection.js:314:9)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Socket.Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
10 replies
DTDrizzle Team
Created by ansipedantic on 12/21/2023 in #help
Migrations with new notNull() columns
(I should add that if I add a .default('bar') it still has the same error... I presume that this default is only applied to newly inserted rows, so it doesn't help fix the existing rows...?)
10 replies