drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[BUG]: TypeError: Cannot read properties of undefined (reading 'primaryKey')

Open aliy321 opened this issue 9 months ago • 10 comments

What version of drizzle-orm are you using?

^0.30.10

What version of drizzle-kit are you using?

^0.21.2

Describe the Bug

There's an issue when i try to run npx drizzle-kit push, keep getting

TypeError: Cannot read properties of undefined (reading 'primaryKey')
    at logSuggestionsAndReturn2

base on this discord post: https://discord.com/channels/1043890932593987624/1151920448049782915/1240052746770710578

Was able to temporarily fix it by monkey patching the bin.cjs file referenced in the error, simply by adding optional chaining like so
Image
You guys should probably consider adding  "noUncheckedIndexedAccess": true, to Drizzle-kit tsconfig.json, 
otherwise these kinds of errors will always keep popping up

Expected behavior

dotenv drizzle-kit push

drizzle-kit: v0.21.2 drizzle-orm: v0.30.10

Warning You are about to execute current statements:

ALTER TABLE posts DROP COLUMN image;

[✓] Changes applied

Environment & setup

No response

aliy321 avatar May 15 '24 14:05 aliy321

This should be fixed in [email protected]. If the issue persists, feel free to reopen it!

AndriiSherman avatar May 22 '24 14:05 AndriiSherman

I am having the same issue: drizzle-kit 0.24.2 drizzle-orm 0.33.0

mrwokkel avatar Aug 28 '24 08:08 mrwokkel

Hi, @AndriiSherman

When I executed pnpm db:push, it prompted me:

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

But in fact, I just deleted a field. I deleted the embedding field.

export const products = sqliteTable('products', {
  id: text('id')
    .$default(() => createId())
    .primaryKey(),
  ...
  embedding: blob('embedding', { mode: 'buffer' }),
  ...
})

drizzle-kit -> 0.24.2 drizzle-orm -> 0.33.0

evanlong0803 avatar Aug 28 '24 15:08 evanlong0803

Same error!

tinsever avatar Aug 29 '24 10:08 tinsever

Hi, @AndriiSherman

When I executed pnpm db:push, it prompted me:

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

But in fact, I just deleted a field. I deleted the embedding field.

export const products = sqliteTable('products', {
  id: text('id')
    .$default(() => createId())
    .primaryKey(),
  ...
  embedding: blob('embedding', { mode: 'buffer' }),
  ...
})

drizzle-kit -> 0.24.2 drizzle-orm -> 0.33.0

Hi, @evanlong0803

I removed the column inside my SQLite using SQLiteStudio. Then I pushed it again and it worked. I mean it's not ideal but yeah.

tinsever avatar Aug 29 '24 10:08 tinsever

hey please don't close this, this is a huge problem.

matannahmani avatar Sep 06 '24 12:09 matannahmani

I am experiencing the same error.

chocokrizpis avatar Sep 06 '24 22:09 chocokrizpis

Same error, please reopen!

vladisavage avatar Sep 07 '24 12:09 vladisavage

Same problem!

vincent-thomas avatar Sep 17 '24 21:09 vincent-thomas

Having the same error I'm using turso

This is my setup:

import { type Config } from "drizzle-kit";
import { env } from "@repo/env";

export default {
  schema: "./schema.ts",
  dialect: "sqlite",
  driver: "turso",
  out: "./migrations",
  dbCredentials: {
    url: env.TURSO_CONNECTION_URL!,
    authToken: env.TURSO_AUTH_TOKEN!,
  },
  tablesFilter: ["flashcards_*"],
} satisfies Config;
 "dependencies": {
    "@libsql/client": "^0.14.0",
    "drizzle-orm": "^0.33.0"
  },
  "devDependencies": {
    "@types/bun": "latest",
    "drizzle-kit": "^0.24.2"
  },
@repo/db:db:push: TypeError: Cannot read properties of undefined (reading 'primaryKey')
@repo/db:db:push:     at logSuggestionsAndReturn2 (/Users/gaden/Documents/GitHub/project/node_modules/drizzle-kit/bin.cjs:72915:87)
@repo/db:db:push:     at sqlitePush (/Users/gaden/Documents/GitHub/project/node_modules/drizzle-kit/bin.cjs:74866:19)
@repo/db:db:push:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
@repo/db:db:push:     at async Object.handler (/Users/gaden/Documents/GitHub/project/node_modules/drizzle-kit/bin.cjs:83724:9)
@repo/db:db:push:     at async run (/Users/gaden/Documents/GitHub/project/node_modules/drizzle-kit/bin.cjs:82064:7)

G4den avatar Sep 26 '24 07:09 G4den