Can't run drizzle-kit push:pg - error: column is in a primary key
Hi,
I get this error every time i run push:pg error: column "userId" is in a primary key at Parser.parseErrorMessage (/Users/victormesquita/Documents/Projects/MobiData/node_modules/drizzle-kit/index.cjs:40722:98) at Parser.handlePacket (/Users/victormesquita/Documents/Projects/MobiData/node_modules/drizzle-kit/index.cjs:40563:25) at Parser.parse (/Users/victormesquita/Documents/Projects/MobiData/node_modules/drizzle-kit/index.cjs:40487:34) at Socket.<anonymous> (/Users/victormesquita/Documents/Projects/MobiData/node_modules/drizzle-kit/index.cjs:40763:44) at Socket.emit (node:events:513:28) at addChunk (node:internal/streams/readable:324:12) at readableAddChunk (node:internal/streams/readable:297:9) at Readable.push (node:internal/streams/readable:234:10) at TCP.onStreamRead (node:internal/stream_base_commons:190:23) { length: 101, severity: 'ERROR', code: '42P16', detail: undefined, hint: undefined, position: undefined, internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'tablecmds.c', line: '7327', routine: 'ATExecDropNotNull' }
I get this error every time i run push:pg error: column "userId" is in a primary key at Parser.parseErrorMessage (/Users/victormesquita/Documents/Projects/MobiData/node_modules/drizzle-kit/index.cjs:40722:98) at Parser.handlePacket (/Users/victormesquita/Documents/Projects/MobiData/node_modules/drizzle-kit/index.cjs:40563:25) at Parser.parse (/Users/victormesquita/Documents/Projects/MobiData/node_modules/drizzle-kit/index.cjs:40487:34) at Socket.<anonymous> (/Users/victormesquita/Documents/Projects/MobiData/node_modules/drizzle-kit/index.cjs:40763:44) at Socket.emit (node:events:513:28) at addChunk (node:internal/streams/readable:324:12) at readableAddChunk (node:internal/streams/readable:297:9) at Readable.push (node:internal/streams/readable:234:10) at TCP.onStreamRead (node:internal/stream_base_commons:190:23) { length: 101, severity: 'ERROR', code: '42P16', detail: undefined, hint: undefined, position: undefined, internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'tablecmds.c', line: '7327', routine: 'ATExecDropNotNull' }
7 Replies
your migration .sql file(s) has errors
Need more info on the sql to help
@Guilherme Rosado
My migrations still very basic, there no drop on tables that have "userId" column
Weird
Can't find any issues too
It only happen with composite key models
pt-PT?
I think I found the issue
your userId and companyId must be NOT NULL
It's good practice to set it as not null to avoid orphan records
That's it, thank you @Guilherme Rosado