这是我的 schema.ts 文件
export const messages = pgTable("messages", {
id: serial("id").primaryKey(),
chatId: integer("chat_id")
.references(() => chats.id)
.notNull(),
content: text("content").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
role: userSystemEnum("role").notNull(),
});
它抛出错误为:
error: column "created_at" cannot be cast automatically to type timestamp without time zone
at Parser.parseErrorMessage (A:\sark and other\chatpdf-yt-main\node_modules\drizzle-kit\index.cjs:40722:98)
at Parser.handlePacket (A:\sark and other\chatpdf-yt-main\node_modules\drizzle-kit\index.cjs:40563:25)
at Parser.parse (A:\sark and other\chatpdf-yt-main\node_modules\drizzle-kit\index.cjs:40487:34)
at TLSSocket.<anonymous> (A:\sark and other\chatpdf-yt-main\node_modules\drizzle-kit\index.cjs:40763:44)
at TLSSocket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23) {
length: 231,
severity: 'ERROR',
code: '42804',
detail: undefined,
hint: 'You might need to specify "USING created_at::timestamp without time zone".',
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'tablecmds.c',
line: '12302',
routine: 'ATPrepAlterColumnType'
}
对于也显示相同错误的角色:
export const userSystemEnum = pgEnum("user_system_enum", ["system", "user"]);
hint: 'You might need to specify "USING role::user_system_enum".'
我该如何解决这个问题?
我认为你需要重组createdAt,我不太确定这里出了什么问题。但也许这会起作用:
createdAt: timestamp("created_at").defaultNow().notNull(),