gpt4 book ai didi

php - 使用 Laravel 迁移重命名现有列,然后运行 ​​php artisan migrate :refresh successfully

转载 作者:行者123 更新时间:2023-11-29 07:14:58 25 4
gpt4 key购买 nike

我已使用以下代码行成功重命名了先前在不同迁移中创建的现有列:

$table->renameColumn('custom_paper_note', 'custom_primary_paper_note');

但是,现在当我运行 php artisan migrate:refresh 时,出现以下错误:

[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'custom_paper_note'; check that column/key exists (SQL: alter table `line_items` drop `custom_paper_note`)

[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'custom_paper_note'; check that column/key exists

这对我来说很有意义,因为我重命名了该列,现在它无法在迁移:刷新过程中删除它。但是,我不明白如何修复这个错误?

感谢您的帮助。

最佳答案

在同一个迁移文件中,在 down() 函数中,声明重命名的逆操作:

Schema::table('table', function($table){
$table->renameColumn('custom_primary_paper_note', 'custom_paper_note');
});

这样,当您将其恢复时,它会将列重命名为适当的列名称,以便向后兼容。

关于php - 使用 Laravel 迁移重命名现有列,然后运行 ​​php artisan migrate :refresh successfully,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38276388/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com