我正在尝试在 Prisma 项目中运行迁移,但遇到错误“类型“串行”不存在”,即使我使用的是 PostgreSQL 15.8,它应该支持此数据类型。
我已采取的步骤:
我已确保使用最新版本的 Prisma 客户端(@prisma/client:“5.11.0”)。 我检查了我的 PostgreSQL 版本 (psql -V),它是 PostgreSQL 15.8。 我通过删除 node_modules 和 prisma 目录然后重新安装依赖项(npm install)来清除 Prisma 缓存。 我尝试在 PostgreSQL 控制台中手动执行 SQL 迁移,但仍然遇到错误。 我没有安装任何额外的 PostgreSQL 扩展(\dx 仅显示 plpgsql)。 我的迁移文件:
-- AlterTable
ALTER TABLE "ClosedPositions" DROP CONSTRAINT "ClosedPositions_pkey",
ALTER COLUMN "id" SET DATA TYPE SERIAL,
ADD CONSTRAINT "ClosedPositions_pkey" PRIMARY KEY ("id");
-- AlterTable
ALTER TABLE "OpenPositions" DROP CONSTRAINT "OpenPositions_pkey",
ALTER COLUMN "id" SET DATA TYPE SERIAL,
ADD CONSTRAINT "OpenPositions_pkey" PRIMARY KEY ("id");
Error: P3006
Migration `20240920182327_change_id_to_int_in_positions` failed to apply cleanly to the shadow database.
Error:
ERROR: type "serial" does not exist
0: sql_schema_connector::validate_migrations
with namespaces=None
at schema-engine/connectors/sql-schema-connector/src/lib.rs:325
1: schema_core::state::DevDiagnostic
at schema-engine/core/src/state.rs:276
什么可能导致此错误,如何解决?是否存在冲突或配置问题导致 Prisma 无法正确识别串行数据类型?
我也尝试过
npx prisma migrate reset
我收到错误:
Error: P3018
A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve
Migration name: 20240920182327_change_id_to_int_in_positions
Database error code: 42704
Database error:
ERROR: type "serial" does not exist
DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E42704), message: "type \"serial\" does not exist", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_type.c"), line: Some(274), routine: Some("typenameType") }
非常感谢您的帮助
问题是serial不是一种类型,它本质上是一个宏,如链接中所述。该错误来自 Postgres 本身:
create table id_test(id integer);
alter table id_test alter column id type serial;
ERROR: type "serial" does not exist