跳到主要內容

限制與已知問題

以下限制適用於 Prisma Migrate。

不支援 MongoDB 聯結器

Prisma Migrate 目前不支援 MongoDB 聯結器。

你無法自動切換資料庫提供者

Prisma Migrate 生成特定於你的提供者的 SQL 檔案。這意味著你不能在生產環境中使用與 PostgreSQL 相同的遷移檔案,而在開發環境中使用 SQLite,因為遷移檔案中的語法將不相容。

2.15.0 及更高版本中,Prisma Migrate 會檢測遷移是否與配置的提供者不匹配,並列印一條有用的錯誤訊息。例如,如果你的遷移是針對 PostgreSQL 資料庫的,但你的 provider 設定為 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.

為了手動切換資料庫提供者,你必須

  • 更改 schema 中 datasource 塊裡的 providerurl 引數
  • 歸檔或移除現有的遷移歷史 — 不得存在 ./prisma/migrations 資料夾
  • 執行 prisma migrate dev 以開始新的遷移歷史

最後一步會建立一個新的初始遷移,將空資料庫遷移到你當前的 schema.prisma。請注意,

  • 此遷移將包含 schema.prisma 中反映的內容。如果你手動編輯了之前的遷移檔案以新增自定義 SQL,則需要再次自行新增。
  • 使用新提供者建立的新資料庫將不包含任何資料。

重置資料庫時的資料丟失

在開發環境中,Prisma Migrate 有時會提示你重置資料庫。重置會刪除並重新建立資料庫,這會導致資料丟失。資料庫在以下情況下重置:

  • 你顯式呼叫 prisma migrate reset
  • 你呼叫 prisma migrate dev 且 Prisma Migrate 檢測到資料庫偏移或遷移歷史衝突

prisma migrate devprisma migrate reset 命令**僅**設計用於**開發環境**,不應影響生產資料。

當資料庫被重置時,如果 Prisma Migrate 在 package.json 中檢測到種子指令碼,它將觸發資料播種。

注意:有關在資料庫重置時重新建立資料的簡單整合方式,請查閱我們的資料播種指南

Prisma Migrate 和 PgBouncer

如果你嘗試在使用 PgBouncer 進行連線池的環境中執行 Prisma Migrate 命令,你可能會看到以下錯誤

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

有關更多資訊和解決方案,請參閱Prisma Migrate 和 PgBouncer 解決方案。請關注GitHub issue #6485 以獲取更新。

非互動式環境中的 Prisma Migrate

當你從 Node 指令碼或 bash shell 等非互動式環境中(例如 Docker)執行 CLI 命令時,Prisma ORM 會檢測到。發生這種情況時,將顯示警告,指示環境是非互動式的,並且 migrate dev 命令不受支援。

為確保 Docker 環境能夠識別該命令,請以 interactive 模式執行映象,以便它響應 migrate dev 命令。

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

# Example usage
docker run -it node
© . This site is unofficial and not affiliated with Prisma Data, Inc.