我想将一个新表“产品”推送到我的数据库“neon postgresSQL”。
// 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(),
});
我想将其添加到现有架构文件中
//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
我的脚本是:
"db:generate": "npx drizzle-kit generate",
"db:push": "npx drizzle-kit migrate",
当我运行第一个命令时,我在服务器文件夹中得到了这个文件: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()
);
然后我将其推送到我得到的数据库:
applying migrations...error: column "userId" of relation "twoFactorToken" already exists
我该怎么办?
如果有人遇到这个问题,我回滚了表格并一键添加了新的修改