TypeError: Cannot read properties of undefined (reading 'columns') - SQLite TursoDB

pnpm db:push

> [email protected] db:push C:\Users\migue\project
> dotenv drizzle-kit push

drizzle-kit: v0.22.7
drizzle-orm: v0.31.2

No config path provided, using default path
Reading config file 'C:\Users\migue\project\drizzle.config.ts'
[✓] Pulling schema from database...
TypeError: Cannot read properties of undefined (reading 'columns')
at _moveDataStatements (C:\Users\migue\project\node_modules\.pnpm\[email protected]\node_modules\drizzle-kit\bin.cjs:120565:65)
at logSuggestionsAndReturn2 (C:\Users\migue\project\node_modules\.pnpm\[email protected]\node_modules\drizzle-kit\bin.cjs:120787:45)
at sqlitePush (C:\Users\migue\project\node_modules\.pnpm\[email protected]\node_modules\drizzle-kit\bin.cjs:122591:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async _Command.<anonymous> (C:\Users\migue\project\node_modules\.pnpm\[email protected]\node_modules\drizzle-kit\bin.cjs:129691:7)
pnpm db:push

> [email protected] db:push C:\Users\migue\project
> dotenv drizzle-kit push

drizzle-kit: v0.22.7
drizzle-orm: v0.31.2

No config path provided, using default path
Reading config file 'C:\Users\migue\project\drizzle.config.ts'
[✓] Pulling schema from database...
TypeError: Cannot read properties of undefined (reading 'columns')
at _moveDataStatements (C:\Users\migue\project\node_modules\.pnpm\[email protected]\node_modules\drizzle-kit\bin.cjs:120565:65)
at logSuggestionsAndReturn2 (C:\Users\migue\project\node_modules\.pnpm\[email protected]\node_modules\drizzle-kit\bin.cjs:120787:45)
at sqlitePush (C:\Users\migue\project\node_modules\.pnpm\[email protected]\node_modules\drizzle-kit\bin.cjs:122591:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async _Command.<anonymous> (C:\Users\migue\project\node_modules\.pnpm\[email protected]\node_modules\drizzle-kit\bin.cjs:129691:7)
I've seen this problem mentioned here before, but apparently its still present in the newest version of drizzle. I just updated drizzle kit to 0.22.7 and orm to 0.31.2 (latest versions) and the problem persists. Using turso DB
4 Replies
migs
migsOP6mo ago
This is the table I added that causes the problem, I might be missing something but I don't see anything wrong in it. If I remove this table and push again it will correctly apply changes, but I can't push when I add this table. Must be something wrong on this table
export const discountUses = sqLiteTable(
"discountUse",
{
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
discountId: integer("discountId")
.references(() => storeDiscounts.id, {
onDelete: "cascade",
})
.notNull(),
invoiceId: text("invoiceId")
.references(() => storeInvoices.id, {
onDelete: "cascade",
})
.notNull(),
},
(discountUse) => ({
discountUse_id_idxIdIdx: index("discountUse_id_idx").on(discountUse.id),
}),
);

export const discountUsesRelations = relations(discountUses, ({ one }) => ({
discount: one(storeDiscounts, {
fields: [discountUses.discountId],
references: [storeDiscounts.id],
}),
invoice: one(storeInvoices, {
fields: [discountUses.invoiceId],
references: [storeInvoices.id],
}),
}));
export const discountUses = sqLiteTable(
"discountUse",
{
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
discountId: integer("discountId")
.references(() => storeDiscounts.id, {
onDelete: "cascade",
})
.notNull(),
invoiceId: text("invoiceId")
.references(() => storeInvoices.id, {
onDelete: "cascade",
})
.notNull(),
},
(discountUse) => ({
discountUse_id_idxIdIdx: index("discountUse_id_idx").on(discountUse.id),
}),
);

export const discountUsesRelations = relations(discountUses, ({ one }) => ({
discount: one(storeDiscounts, {
fields: [discountUses.discountId],
references: [storeDiscounts.id],
}),
invoice: one(storeInvoices, {
fields: [discountUses.invoiceId],
references: [storeInvoices.id],
}),
}));
Looks like if I push without the foreign keys, it works, and if I add the foreign keys after the table already exists it will work. The problem seems to happen when you create a table with foreign keys from the beggining
migs
migsOP6mo ago
GitHub
[BUG] TypeError: Cannot read properties of undefined (reading 'colu...
After adding the following table : export const discountUses = sqLiteTable( "discountUse", { id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),...
migs
migsOP6mo ago
@Genio
Genio
Genio6mo ago
ah okay my current work around it to type everything in schema file then run db:generate to generate the sql equivalent
Want results from more Discord servers?
Add your server