DT
Drizzle Teamjoshborseth

TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys')

I am attempting to run db push, but I am getting this error above^^ does anyone know what might be going on?
Noahh
Noahh•247d ago
are you able to post the full stack trace and anywhere in your schema you're creating composite primary keys?
joshborseth
joshborseth•247d ago
absolutely! TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys') at /Users/joshuaborseth/Documents/locorum/node_modules/.pnpm/drizzle-kit@0.19.13/node_modules/drizzle-kit/index.cjs:16964:51 at Array.map (<anonymous>) at prepareDeleteCompositePrimaryKeyMySql (/Users/joshuaborseth/Documents/locorum/node_modules/.pnpm/drizzle-kit@0.19.13/node_modules/drizzle-kit/index.cjs:16959:33) at /Users/joshuaborseth/Documents/locorum/node_modules/.pnpm/drizzle-kit@0.19.13/node_modules/drizzle-kit/index.cjs:17352:35 at Array.forEach (<anonymous>) at applySnapshotsDiff (/Users/joshuaborseth/Documents/locorum/node_modules/.pnpm/drizzle-kit@0.19.13/node_modules/drizzle-kit/index.cjs:17277:26) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async prepareSQL (/Users/joshuaborseth/Documents/locorum/node_modules/.pnpm/drizzle-kit@0.19.13/node_modules/drizzle-kit/index.cjs:14879:14) at async prepareMySQLPush (/Users/joshuaborseth/Documents/locorum/node_modules/.pnpm/drizzle-kit@0.19.13/node_modules/drizzle-kit/index.cjs:14698:47) at async Command.<anonymous> (/Users/joshuaborseth/Documents/locorum/node_modules/.pnpm/drizzle-kit@0.19.13/node_modules/drizzle-kit/index.cjs:53223:22) I'll have a look for any composite primary keys... Im not using any, but someone on my team may be using them
Noahh
Noahh•247d ago
gotcha, it looks like this is a known issue: https://github.com/drizzle-team/drizzle-kit-mirror/issues/170
GitHub
Error on removal of composite keys on pgTable in postgres · Iss...
When removed a composite primary key and renamed a pgTable defined: //old const table = pgTable( "table", { id: text("id").notNull(), name: text("name").notNull(), }, ...
Noahh
Noahh•247d ago
maybe a primary key was removed from your schema recently?
joshborseth
joshborseth•247d ago
yeah I switched from using auto incrementing Ids to using uids so Im thinking that would do it
Noahh
Noahh•247d ago
interesting apparently reverting back, generating, then generating again helped someone? https://discord.com/channels/1043890932593987624/1070810929475883038/1145412231392149545
joshborseth
joshborseth•247d ago
hmm okay, ill give that a try got it working! thanks for your help @Noahh !!
Noahh
Noahh•247d ago
sweet
Rodrigo
Rodrigo•58d ago
For me this is happening when I'm simply renaming a table to uses a composite key of two other tables. Any idea how to resolve this? See https://discord.com/channels/1043890932593987624/1220342370957000724
Amruth Pillai
Amruth Pillai•9d ago
I'm getting this error when running drizzle-kit push on the latest version (0.21.0) as well, with the postgresql dialect. The schema has a lot of tables with composite primary keys, but most of them look like this:
export const workOrderTemplateUserTable = pgTable(
"work_order_template_user",
{
templateId: text("template_id")
.notNull()
.references(() => workOrderTemplateTable.id, { onDelete: "cascade" }),
userId: text("user_id")
.notNull()
.references(() => userTable.id, { onDelete: "cascade" }),
createdAt: timestampType("created_at"),
createdById: text("created_by_id").references(() => userTable.id, { onDelete: "set null" }),
},
(t) => ({
primaryKey: primaryKey({ columns: [t.templateId, t.userId] }),
}),
);
export const workOrderTemplateUserTable = pgTable(
"work_order_template_user",
{
templateId: text("template_id")
.notNull()
.references(() => workOrderTemplateTable.id, { onDelete: "cascade" }),
userId: text("user_id")
.notNull()
.references(() => userTable.id, { onDelete: "cascade" }),
createdAt: timestampType("created_at"),
createdById: text("created_by_id").references(() => userTable.id, { onDelete: "set null" }),
},
(t) => ({
primaryKey: primaryKey({ columns: [t.templateId, t.userId] }),
}),
);
This used to work as expected in the older versions, but it's become a problem now.
Tobi
Tobi•8d ago
yea same im getting issue as well. It used to work before updating
doogilie
doogilie•7d ago
same here
Ttttmizer
Ttttmizer•7d ago
having the same issue. I thought I was doing something wrong, but seeing all you having the same issue, I am guessing it's the docs or the tool that has issues? 🙂
DiamondDragon
DiamondDragon•7d ago
same @Andrew Sherman is this perhaps a more significant issue on the latest drizzle-kit version? seems like more people having issues. I tried to revert back to the last version and drizzle kit keeps wanting to drop columns with the pk in the comp pk even though there are no changes in the schema when running push. So I am not sure how to get past this using push at least, i keep getting Cannot read properties of undefined (reading 'compositePrimaryKeys')
Ttttmizer
Ttttmizer•6d ago
had it in the previous version too, so it's last two at least I think. I know it happens for me if I want to add certain kind of keys, so there is a workaround so far, and I also didn't try it directly with SQL instead of ORM methods
DiamondDragon
DiamondDragon•6d ago
Yeah I guess you can just write a sql file, kind of hard to keep track of if you're just iterating using push tho.. I haven't been able to get any of the solutions to work for me tho, so I am just stuck using single pk's on a few join tables
Ttttmizer
Ttttmizer•6d ago
same. hoping some future release will actually fix this 😄
Andrii Sherman
Andrii Sherman•6d ago
we are grouping all new kit issue and will do a patch release, I hope today/tomorrow we can release a new patch for it
adambarito
adambarito•4d ago
Same. Had no issues with drizzle-kit 0.20.17, and started seeing this compositePrimaryKeys error in 0.21.0 onwards.
Mika
Mika•4d ago
@Andrew Sherman new version (0.21.2) experiencing similar issue but with primaryKey
TypeError: Cannot read properties of undefined (reading 'primaryKey')
at logSuggestionsAndReturn2 (node_modules/drizzle-kit/bin.cjs:104764:87)
at sqlitePush (node_modules/drizzle-kit/bin.cjs:106845:19)
at async Command.<anonymous> (node_modules/drizzle-kit/bin.cjs:113749:7)
TypeError: Cannot read properties of undefined (reading 'primaryKey')
at logSuggestionsAndReturn2 (node_modules/drizzle-kit/bin.cjs:104764:87)
at sqlitePush (node_modules/drizzle-kit/bin.cjs:106845:19)
at async Command.<anonymous> (node_modules/drizzle-kit/bin.cjs:113749:7)
Was able to temporarily fix it by monkey patching the bin.cjs file referenced in the error, simply by adding optional chaining like so
No description
Mika
Mika•4d ago
You guys should probably consider adding "noUncheckedIndexedAccess": true, to Drizzle-kit tsconfig.json, otherwise these kinds of errors will always keep popping up
Aliy Akhbar
Aliy Akhbar•3d ago
are they fixing this issue? TypeError: Cannot read properties of undefined (reading 'primaryKey')
Andrii Sherman
Andrii Sherman•3d ago
yeah, I've included not all fixes on 0.21.2 working on fixing others
Want results from more Discord servers?
Add your server
More Posts
Nesting sqlite drizzle into a deeper location in my ts app, difficulties with src/ vs dist/Hey! I'm very new to drizzle and trying to set up a very small drizzle instance for a service that rsyntax highlighting not workingI reinstalled the node_modules multiple times and it didnt fix my problem. This isnt suposed to lookPrepare raw sql query (Postgres)Hi, I need to do a recursive query, so I think I need to use the magic sql operator to build it. Is packing migration files with the libraryhey there, I'm trying to use `migrate` inside from a library consumer (i.e I have a `@mycompany/db-lAny way to invoke a SQL function?For ex: lets say I declare a SQL function `CREATE OR REPLACE FUNCTION do_something()` how do i invoHow to include array literals in raw sql?I have an input array used for an order by using the array_position function - rather than passing tMySQL Table SchemasI need to generate the following structure of tables: `1. Sales 2.Sales ....` Currently if I use wany way to automatically cast numeric types on retrieval?I have a numeric field in a video table: ``` export const VideoTable = pgTable('videos', { id: uuiQuery in drizzle doesn't work## Error: ```console DrizzleError: No fields selected for table "usersToGroups" ("users_groups") ``Cannot read properties of undefined (reading 'referencedTable')Seemingly getting this error out of nowhere. I believe it's related to the relations I defined, but Relational query builder in mysql?I cant find anything about how to implement this. Am I blind or is this impossible?TransactionRollbackErrorNeed some help understanding TransactionRollbackError... Is this error saying the `tx.rollback()` fPostgresError: null value in column "id" of relation "pairs" violates not-null constraintHello, I am fairly new to Drizzle and working with databases, so I am running into a problem that I OnConflictDoNothing with mysqlHi everyone, I want to use the on conflict do nothing method described here: https://orm.drizzle.teadrizzle-kit introspect reorder tablesHere is the case: - I have a remote database. I made a backup and restore it locally - I ran: drizzMigration custom loggerHey there, I'm want to run migration as part of my CI/CD, and would have liked the output of the `miwhy do snapshots not have the same name as the migrations?Hey, loving dirzzle so far. Hit a snag recently. Me and my friend are collaborating on a project. Help with improving database queryHello, I am seeking advice on how to improve a database query I am currently working with. My objectTypescript types for relational queries with neon dbHey, I am having an issue with typescript types for relational queries with drizzle and neon db. Det.onUpdateNow() for postgresql?is that possible?