Skip to main content

限制和已知问题

以下限制适用于 Prisma Migrate。

¥The following limitations apply to Prisma Migrate.

不支持 MongoDB 连接器

¥MongoDB connector not supported

Prisma Migrate 目前不支持 MongoDB 连接器。

¥Prisma Migrate does not currently support the MongoDB connector.

你无法自动切换数据库提供商

¥You cannot automatically switch database providers

Prisma Migrate 生成特定于你的提供商的 SQL 文件。这意味着你不能在生产中为 PostgreSQL 使用相同的迁移文件,在开发中为 SQLite 使用相同的迁移文件,因为迁移中的语法不兼容。

¥Prisma Migrate generates SQL files that are specific to your provider. This means that you cannot use the same migration files for PostgreSQL in production and SQLite in development, because the syntax in the migrations will be incompatible.

2.15.0 及更高版本中,Prisma Migrate 会检测迁移何时与配置的提供程序不匹配并打印有用的错误消息。例如,如果你的迁移针对 PostgreSQL 数据库,但你的 provider 设置为 mysql

¥In 2.15.0 and later, Prisma Migrate detects when the migrations do not match the configured provider and prints a helpful error message. For example, if your migrations are for a PostgreSQL database but your provider is set to mysql:

Error: P3014

The datasource provider `postgresql` specified in your schema does not match the one specified in the migration_lock.toml, mysql. Please remove your current migration directory and start a new migration history with prisma migrate dev.

为了手动切换数据库提供商,你必须:

¥In order to manually switch the database provider, you must:

  • 更改架构中 datasource 块中的 providerurl 参数

    ¥Change the provider and url parameters in the datasource block in your schema

  • 存档或删除你现有的迁移历史记录 - 不能有 ./prisma/migrations 文件夹

    ¥Archive or remove your existing migration history - there must not be a ./prisma/migrations folder

  • 运行 prisma migrate dev 以开始新的迁移历史记录

    ¥Run prisma migrate dev to start a new migration history

最后一步创建一个新的初始迁移,从空数据库到当前的 schema.prisma。意识到:

¥The last step creates a new initial migration that goes from an empty database to your current schema.prisma. Be aware that:

  • 此迁移将仅包含 schema.prisma.ini 中反映的内容。如果你手动编辑以前的迁移文件来添加自定义 SQL,你将需要再次自行添加。

    ¥This migration will only contain what is reflected in your schema.prisma. If you manually edited your previous migration files to add custom SQL you will need to again add this yourself.

  • 使用新提供程序新创建的数据库将不包含任何数据。

    ¥The newly created database using the new provider will not contain any data.

重置数据库时数据丢失

¥Data loss when resetting database

在开发环境中,Prisma Migrate 有时会提示你重置数据库。重置会删除并重新创建数据库,这会导致数据丢失。数据库在以下情况下重置:

¥In a development environment, Prisma Migrate sometimes prompts you to reset the database. Resetting drops and recreates the database, which results in data loss. The database is reset when:

  • 你显式调用 prisma migrate reset

    ¥You call prisma migrate reset explicitly

  • 你调用 prisma migrate dev,Prisma Migrate 检测到数据库中的偏差或迁移历史记录冲突

    ¥You call prisma migrate dev and Prisma Migrate detects drift in the database or a migration history conflict

prisma migrate devprisma migrate reset 命令仅设计用于开发,不应影响生产数据。

¥The prisma migrate dev and prisma migrate reset commands are designed to be used in development only, and should not affect production data.

当数据库重置时,如果 Prisma Migrate 检测到 package.json 中的种子脚本,它将触发播种。

¥When the database is reset, if Prisma Migrate detects a seed script in package.json, it will trigger seeding.

注意:如需在数据库重置时重新创建数据的简单且集成的方法,请查看我们的 播种指南

¥Note: For a simple and integrated way to re-create data when the database is reset, check out our seeding guide.

Prisma Migrate 和 PgBouncer

¥Prisma Migrate and PgBouncer

如果你尝试在使用 PgBouncer 进行连接池的环境中运行 Prisma Migrate 命令,你可能会看到以下错误:

¥You might see the following error if you attempt to run Prisma Migrate commands in an environment that uses PgBouncer for connection pooling:

Error: undefined: Database error
Error querying the database: db error: ERROR: prepared statement "s0" already exists

请参阅 Prisma Migrate 和 PgBouncer 解决方法 了解更多信息和解决方法。关注 GitHub 问题 #6485 获取更新。

¥See Prisma Migrate and PgBouncer workaround for further information and a workaround. Follow GitHub issue #6485 for updates.

非交互式环境中的 Prisma Migrate

¥Prisma Migrate in non-interactive environments

Prisma ORM 会检测你何时在非交互式环境(例如 Docker)中从 Node 脚本或 bash shell 运行 CLI 命令。发生这种情况时,会显示一条警告,指示环境是非交互式的并且不支持 migrate dev 命令。

¥Prisma ORM detects when you run CLI commands in non-interactive environments, such as Docker, from Node scripts or in bash shells. When this happens a warning displays, indicating that the environment is non-interactive and the migrate dev command is not supported.

为了确保 Docker 环境拾取该命令,请在 interactive 模式下运行该映像,以便它对 migrate dev 命令做出反应。

¥To ensure the Docker environment picks up the command, run the image in interactive mode so that it reacts to the migrate dev command.

docker run --interactive --tty <image name>
# or
docker -it <image name>

# Example usage
docker run -it node