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?
33 Replies
are you able to post the full stack trace and anywhere in your schema you're creating composite primary keys?
absolutely!
TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys')
at /Users/joshuaborseth/Documents/locorum/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:16964:51
at Array.map (<anonymous>)
at prepareDeleteCompositePrimaryKeyMySql (/Users/joshuaborseth/Documents/locorum/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:16959:33)
at /Users/joshuaborseth/Documents/locorum/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:17352:35
at Array.forEach (<anonymous>)
at applySnapshotsDiff (/Users/joshuaborseth/Documents/locorum/node_modules/.pnpm/[email protected]/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/[email protected]/node_modules/drizzle-kit/index.cjs:14879:14)
at async prepareMySQLPush (/Users/joshuaborseth/Documents/locorum/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:14698:47)
at async Command.<anonymous> (/Users/joshuaborseth/Documents/locorum/node_modules/.pnpm/[email protected]/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
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(), }, ...
maybe a primary key was removed from your schema recently?
yeah I switched from using auto incrementing Ids to using uids
so Im thinking that would do it
interesting
apparently reverting back, generating, then generating again helped someone? https://discord.com/channels/1043890932593987624/1070810929475883038/1145412231392149545
hmm okay, ill give that a try
got it working!
thanks for your help @Noahh !!
sweet
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
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:
This used to work as expected in the older versions, but it's become a problem now.yea same im getting issue as well. It used to work before updating
same here
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? 🙂
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')
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
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
same. hoping some future release will actually fix this 😄
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
Same. Had no issues with drizzle-kit 0.20.17, and started seeing this compositePrimaryKeys error in 0.21.0 onwards.
@Andrew Sherman new version (0.21.2) experiencing similar issue but with
primaryKey
Was able to temporarily fix it by monkey patching the bin.cjs
file referenced in the error, simply by adding optional chaining like soYou guys should probably consider adding
"noUncheckedIndexedAccess": true,
to Drizzle-kit tsconfig.json
,
otherwise these kinds of errors will always keep popping upare they fixing this issue? TypeError: Cannot read properties of undefined (reading 'primaryKey')
yeah, I've included not all fixes on 0.21.2
working on fixing others
Any workaround for the
compositePimaryKeys
issue perhaps? Not being able to generate migrations is a real pain 🙏Hi there.
I was facing the issue with
TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys')
In my case, I am using postgres and the 'public' schema.
I was using drizzle-kit 0.21.2 I had to monkeypatch the applyPgSnapshotsDiff function in node_modules/drizzle-kit/bin.cjs to add a fallback to public when the schema is empty in the functions that were causing issues.
Doing that, it no longer fails for me. My guess is that schema configuration should come from somewhere else but couldn't find it.Should be fixed in 0.21.3
https://discord.com/channels/1043890932593987624/1235937884956000377/1242851388535607316
Would suggest to subscribe to kit notifications role
I upgraded to 0.21.4 and still have the same error, when running push on an empty database it works for the first time but after that I keep getting
Cannot read properties of undefined (reading 'compositePrimaryKeys')
Here is my pgtable
got it, thanks for a schema. fixing it
I've been seeing the
Cannot read properties of undefined (reading 'compositePrimaryKeys')
as well. Upgraded to 0.21.3 and now whenever I db push
, it tells me:
I have not made any changes to this table and even if I db push
several times in a row, it always says the same thing. Upgrading to 0.21.4 didn't fix this.
Here that table's schema:
Updating the schema to the following works, but I'd imagine both would be valid, no?
From 0.21.4 I can still reproduce the issue.
Example schema:
Running the schema on an empty database works, running it a second time fails with the error
The names of the tables seem to matter. Switching, for example, the bridge table name to 'bridge_table' I can get
Pulling schema from database...error: column "bbbb_bbbbb_bbbb_test" is in a primary key
Hope this helps. All tables are in the 'public' schema.solution if the table name is too long then you need to set a primaryKey custom name
my column names are not too long, but still having the same issue. I can't even push the same migration after regenerating them from scratch. I tried giving custom names to composite keys but didn't work as well.
kit version: 0.22.2
orm version: 0.31.1