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' }
7 Replies
Guilherme Rosado
Guilherme Rosado17mo ago
your migration .sql file(s) has errors Need more info on the sql to help
victormesquita.
victormesquita.OP17mo ago
@Guilherme Rosado
victormesquita.
victormesquita.OP17mo ago
My migrations still very basic, there no drop on tables that have "userId" column
Guilherme Rosado
Guilherme Rosado17mo ago
Weird Can't find any issues too
victormesquita.
victormesquita.OP17mo ago
It only happen with composite key models
Guilherme Rosado
Guilherme Rosado17mo ago
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
victormesquita.
victormesquita.OP17mo ago
That's it, thank you @Guilherme Rosado

Did you find this page helpful?