Drizzle kit SQL error

Hi all, I'm getting this weird error when I try to push my schema changes using drizzle-kit push and I have no idea where to begin to solve it:
Error: unknown: uncaught panic: interface conversion: interface is nil, not sqlparser.Expr, vtgate: http://
pscluster-xkj7v0lvx1yw-aws-uswest2a-2-vtgate-6cd24c1e-84962nl82:15000/
at PromiseConnection.execute (C:\Users\jrrvd\Desktop\Projects\dcap-docgen\node_modules\drizzle-kit\inde
x.cjs:35435:26)
at fromDatabase (C:\Users\jrrvd\Desktop\Projects\dcap-docgen\node_modules\drizzle-kit\index.cjs:11845:3
3)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async mysqlPushIntrospect (C:\Users\jrrvd\Desktop\Projects\dcap-docgen\node_modules\drizzle-kit\inde
x.cjs:37725:19)
at async Command.<anonymous> (C:\Users\jrrvd\Desktop\Projects\dcap-docgen\node_modules\drizzle-kit\inde
x.cjs:53103:31) {
code: 'ER_UNKNOWN_ERROR',
errno: 1105,
sql: 'SELECT table_name, column_name\n' +
' FROM information_schema.table_constraints t\n' +
' LEFT JOIN information_schema.key_column_usage k\n' +
' USING(constraint_name,table_schema,table_name)\n' +
" WHERE t.constraint_type='PRIMARY KEY'\n" +
" and table_name != '__drizzle_migrations'\n" +
' AND t.table_schema = ?',
sqlState: 'HY000',
sqlMessage: 'unknown: uncaught panic: interface conversion: interface is nil, not sqlparser.Expr, vtgate:
http://pscluster-xkj7v0lvx1yw-aws-uswest2a-2-vtgate-6cd24c1e-84962nl82:15000/'
}
Error: unknown: uncaught panic: interface conversion: interface is nil, not sqlparser.Expr, vtgate: http://
pscluster-xkj7v0lvx1yw-aws-uswest2a-2-vtgate-6cd24c1e-84962nl82:15000/
at PromiseConnection.execute (C:\Users\jrrvd\Desktop\Projects\dcap-docgen\node_modules\drizzle-kit\inde
x.cjs:35435:26)
at fromDatabase (C:\Users\jrrvd\Desktop\Projects\dcap-docgen\node_modules\drizzle-kit\index.cjs:11845:3
3)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async mysqlPushIntrospect (C:\Users\jrrvd\Desktop\Projects\dcap-docgen\node_modules\drizzle-kit\inde
x.cjs:37725:19)
at async Command.<anonymous> (C:\Users\jrrvd\Desktop\Projects\dcap-docgen\node_modules\drizzle-kit\inde
x.cjs:53103:31) {
code: 'ER_UNKNOWN_ERROR',
errno: 1105,
sql: 'SELECT table_name, column_name\n' +
' FROM information_schema.table_constraints t\n' +
' LEFT JOIN information_schema.key_column_usage k\n' +
' USING(constraint_name,table_schema,table_name)\n' +
" WHERE t.constraint_type='PRIMARY KEY'\n" +
" and table_name != '__drizzle_migrations'\n" +
' AND t.table_schema = ?',
sqlState: 'HY000',
sqlMessage: 'unknown: uncaught panic: interface conversion: interface is nil, not sqlparser.Expr, vtgate:
http://pscluster-xkj7v0lvx1yw-aws-uswest2a-2-vtgate-6cd24c1e-84962nl82:15000/'
}
I am using PlanetScale as my database provider.
7 Replies
Jonathan
JonathanOP•2y ago
This is my schema file:
import { relations, sql } from "drizzle-orm";
import {
mysqlTable,
timestamp,
text,
varchar,
json,
} from "drizzle-orm/mysql-core";

export const users = mysqlTable("users", {
id: varchar("id", { length: 255 }).primaryKey(),
externalId: text("externalId"),

firstName: text("firstName").notNull(),
lastName: text("lastName").notNull(),

createdAt: timestamp("createdAt")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updatedAt")
.default(sql`CURRENT_TIMESTAMP`)
.onUpdateNow()
.notNull(),
});

export const usersRelations = relations(users, ({ many }) => ({
documents: many(documents),
}));

export const documents = mysqlTable("documents", {
id: varchar("id", { length: 255 }).primaryKey(),

type: text("type").notNull(),
name: text("name").notNull(),
answers: json("answers"),

userId: text("userId"),

createdAt: timestamp("createdAt")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updatedAt")
.default(sql`CURRENT_TIMESTAMP`)
.onUpdateNow()
.notNull(),
});

export const documentsRelations = relations(documents, ({ one }) => ({
user: one(users, { fields: [documents.userId], references: [users.id] }),
}));
import { relations, sql } from "drizzle-orm";
import {
mysqlTable,
timestamp,
text,
varchar,
json,
} from "drizzle-orm/mysql-core";

export const users = mysqlTable("users", {
id: varchar("id", { length: 255 }).primaryKey(),
externalId: text("externalId"),

firstName: text("firstName").notNull(),
lastName: text("lastName").notNull(),

createdAt: timestamp("createdAt")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updatedAt")
.default(sql`CURRENT_TIMESTAMP`)
.onUpdateNow()
.notNull(),
});

export const usersRelations = relations(users, ({ many }) => ({
documents: many(documents),
}));

export const documents = mysqlTable("documents", {
id: varchar("id", { length: 255 }).primaryKey(),

type: text("type").notNull(),
name: text("name").notNull(),
answers: json("answers"),

userId: text("userId"),

createdAt: timestamp("createdAt")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updatedAt")
.default(sql`CURRENT_TIMESTAMP`)
.onUpdateNow()
.notNull(),
});

export const documentsRelations = relations(documents, ({ one }) => ({
user: one(users, { fields: [documents.userId], references: [users.id] }),
}));
And my db.ts file:
import { drizzle } from "drizzle-orm/planetscale-serverless";
import { connect } from "@planetscale/database";
import * as schema from "./schema";

const client = connect({
url: process.env.DATABASE_URL as string,
});
const db = drizzle(client, { schema });

export default db;
import { drizzle } from "drizzle-orm/planetscale-serverless";
import { connect } from "@planetscale/database";
import * as schema from "./schema";

const client = connect({
url: process.env.DATABASE_URL as string,
});
const db = drizzle(client, { schema });

export default db;
A side note: The code base I am working in is a fork of another project I am working on. I want to give this fork its own database. Okay I figured out the issue, but I still dont have a solution. If I use the connection string from the original project inside of my forked project, then drizzle-kit push works perfectly fine.
SammyJoyce
SammyJoyce•17mo ago
https://github.com/drizzle-team/drizzle-orm/issues/472 I have the same issue. Can't find a fix for onUpdateNow()
GitHub
[BUG]: planetscale - now() and current_timestamp() doesn't work whe...
What version of drizzle-orm are you using? 0.23.13 What version of drizzle-kit are you using? 0.17.4 Describe the Bug Create table fails on planetscale if FSP not specified for now() and current_ti...
thecmdrunner
thecmdrunner•17mo ago
🥲 OnUpdateNow is kind of important!
SammyJoyce
SammyJoyce•17mo ago
updatedAt: datetime("updated_at", { mode: "date", fsp: 3 }).default(
sql.raw(`NULL ON UPDATE CURRENT_TIMESTAMP(3)`),
),
updatedAt: datetime("updated_at", { mode: "date", fsp: 3 }).default(
sql.raw(`NULL ON UPDATE CURRENT_TIMESTAMP(3)`),
),
This seems to be working
thecmdrunner
thecmdrunner•17mo ago
works everytime the row is updated? Or only when the row is created?
SammyJoyce
SammyJoyce•17mo ago
Updated. The ‘null’ is the default when created, and but it retains the ON UPDATE at the end of the sql query, so updates, on update
thecmdrunner
thecmdrunner•16mo ago
awesome! Thanks for the snippet 😄
Want results from more Discord servers?
Add your server