Drizzle kit migration and pushing

  Kiến thức lập trình

i want to push to my db ‘neon postgresSQL’ a new table “products”.

// Define the products table
export const products = pgTable("products", {
  id: serial("id").primaryKey(),
  title: text("title").notNull(),
  description: text("description").notNull(),
  price: real("price").notNull(),
  createdAt: timestamp("created").defaultNow(),

i want to add it to an existing schema file

//other tables .... 

// Define the twoFactorTokens table
export const twoFactorTokens = pgTable(
    id: text("id")
      .$defaultFn(() => createId()),
    token: text("token").notNull(),
    expires: timestamp("expires", { mode: "date" }).notNull(),
    email: text("email").notNull(),
    userId: text("userId").references(() => users.id, { onDelete: "cascade" }),
  (verificationToken) => ({
    compoundKey: primaryKey({
      columns: [verificationToken.id, verificationToken.token],

//here i added the product table

my scripts are:

"db:generate": "npx drizzle-kit generate",
"db:push": "npx drizzle-kit migrate",

when i run the first command i got this file in the server folder:0008_peaceful_meltdown.sql

    "id" serial PRIMARY KEY NOT NULL,
    "title" text NOT NULL,
    "description" text NOT NULL,
    "price" real NOT NULL,
    "created" timestamp DEFAULT now()

then i push it to the db i got:
applying migrations...error: column "userId" of relation "twoFactorToken" already exists

what should i do?

New contributor

Wesam Muneer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website