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(
"twoFactorToken",
{
id: text("id")
.notNull()
.$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
CREATE TABLE IF NOT EXISTS "products" (
"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