英文:
How to fix the used key part isn't a string, doesn't support unique prefix keys from prisma migrtion?
问题
我在本地使用Prisma开发了一个MySQL数据库,一切都正常,直到我决定迁移到外部环境,这时迁移失败了:
-- DropForeignKey
ALTER TABLE `Invoices` DROP FOREIGN KEY `Invoices_promoCodesId_fkey`;
-- AlterTable
ALTER TABLE `Invoices` DROP COLUMN `promoCodesId`,
ADD COLUMN `PromoCodesId` INTEGER NULL;
-- AddForeignKey
ALTER TABLE `Invoices` ADD CONSTRAINT `Invoices_PromoCodesId_fkey` FOREIGN KEY (`PromoCodesId`) REFERENCES `PromoCodes`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
错误信息:
数据库错误代码:1089
数据库错误:
前缀键不正确;使用的键部分不是字符串,使用的长度超过了键部分的长度,或者存储引擎不支持唯一前缀键
我该如何修复这个问题?
英文:
I developed locally a MySQL database via prisma and it worked fine until I decided to move out to an external environment, and that's where migration failed:
-- DropForeignKey
ALTER TABLE `Invoices` DROP FOREIGN KEY `Invoices_promoCodesId_fkey`;
-- AlterTable
ALTER TABLE `Invoices` DROP COLUMN `promoCodesId`,
ADD COLUMN `PromoCodesId` INTEGER NULL;
-- AddForeignKey
ALTER TABLE `Invoices` ADD CONSTRAINT `Invoices_PromoCodesId_fkey` FOREIGN KEY (`PromoCodesId`) REFERENCES `PromoCodes`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
Error:
Database error code: 1089
Database error:
Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys
How do I fix it?
答案1
得分: 0
很抱歉,我没有找到解决这个问题的方法。
相反,我通过压缩迁移来解决了它。在共享开发环境或正在运行的生产项目中,请不要这样做。
步骤:
- 删除
prisma/migrations
文件夹 - 完全删除本地开发数据库
- 运行
prisma migrate dev
创建一个代表实际状态的单个迁移 - 在有问题的生产数据库上运行
prisma migrate reset
英文:
Unfortunately, I did not find the fix to this issue.
Instead I resolved it squashing the migrations. Don't do this in a shared development environment or on a running production project.
Steps:
- removed the
prisma/migrations
folder - dropped the local development database entirely
- ran
prisma migrate dev
to create a single migration that represents the actual state - ran
prisma migrate reset
on problematic production database
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论