Drizzle Studio giving error due to `CURRENT_TIMESTAMP` in schema

I am having some issues with drizzle studio. I am not able to query the results when there is a CURRENT_TIMESTAMP included in my schema.

See schema on drizzle studio in the first image "1. schema" attached, it is having an error on line no. 20 for CURRENT_TIMESTAMP
Error = Cannot find name 'CURRENT_TIMESTAMP'.

When I try to fetch data using the query db.select().from(userCity); , in the "queries" tab. See the second image "2. queries".

It shows error dialog, with error on console ReferenceError: CURRENT_TIMESTAMP is not defined. See the third image "3. error".

whereas the same query in "sql" section is able to fetch the data. See the fourth image "4. sql".

Also, if in my schema, there are tables with no CURRENT_TIMESTAMP in it, it works as expected with no error.

My Drizzle Config:
import type { Config } from "drizzle-kit";

const uri = [
  "mysql://",
  process.env.DB_USERNAME,
  ":",
  process.env.DB_PASSWORD,
  "@",
  process.env.DB_HOST,
  ":3306/",
  process.env.DB_NAME,
].join("");

export default {
  schema: "../schema/src/tables",
  out: "../schema/drizzle",
  driver: "mysql2",
  dbCredentials: { uri },
  tablesFilter: ["*"],
} satisfies Config;


My Drizzle Schema:
import { sql } from "drizzle-orm";
import { int, primaryKey, timestamp, varchar } from "drizzle-orm/mysql-core";

import { tableCreator } from "./_table";

export const userCity = tableCreator(
  "user_city",
  {
    cityid: int("CITYID").autoincrement().notNull(),
    cityname: varchar("CITYNAME", { length: 100 }).notNull(),
    state: varchar("STATE", { length: 100 }),
    udpateby: int("UDPATEBY").notNull(),
    update: timestamp("UPDATE", { mode: "date" })
      .default(sql`CURRENT_TIMESTAMP`)
      .onUpdateNow()
      .notNull(),
  },
  (table) => {
    return {
      userCityCityid: primaryKey({
        columns: [table.cityid],
        name: "user_city_CITYID",
      }),
    };
  },
);
1_schema.png
2_queries.png
3_error.png
4_sql.png
Was this page helpful?