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

$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


这对我来说很有意义,因为我重命名了该列,现在它无法在migration:refresh过程中删除它。但是,我不知道如何解决此错误?

谢谢你的帮助。

最佳答案

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

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


这样,当您将其放回原处时,会将列重命名为适当的列名称,以便向后兼容。

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

10-12 00:48
查看更多