【问题标题】:Laravel migrate failing on "renameColumn" when running运行时 Laravel 迁移在“renameColumn”上失败
【发布时间】:2020-05-27 07:40:31
【问题描述】:

我有大约 30 多个迁移文件。

当它进入包含列重命名的迁移时:

Schema::table('table', function (Blueprint $table) {
 $table->renameColumn('old_field', 'new_field');
});

只有在进行此迁移时才会出错(比如第 15 次)。它运行所有其他迁移就好了。如果我将其注释掉,那么它将按预期完成。

我运行php artisan migratephp artisan migrate:fresh

我收到以下错误:

 ErrorException  : The "name" column option is not supported, setting it is deprecated and will cause an error in Doctrine 3.0

  at /Volumes/Workspace/new-app-backend/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Column.php:85
    81|                 @trigger_error(sprintf(
    82|                     'The "%s" column option is not supported,' .
    83|                     ' setting it is deprecated and will cause an error in Doctrine 3.0',
    84|                     $name
  > 85|                 ), E_USER_DEPRECATED);
    86| 
    87|                 continue;
    88|             }
    89|             $this->$method($value);

  Exception trace:

  1   trigger_error("The "name" column option is not supported, setting it is deprecated and will cause an error in Doctrine 3.0")
      /Volumes/Workspace/new-app-backend/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Column.php:85

  2   Doctrine\DBAL\Schema\Column::setOptions()
      /Volumes/Workspace/new-app-backend/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Column.php:67

php -v 给了我这个:

PHP 7.3.14 (cli) (built: Jan 24 2020 03:04:31) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.14, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.9.2, Copyright (c) 2002-2020, by Derick Rethans
    with Zend OPcache v7.3.14, Copyright (c) 1999-2018, by Zend Technologies

Mysql -v 给了我这个:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 323
Server version: 5.7.29 Homebrew

我正在使用 "doctrine/dbal": "~2.3"

此错误仅在我的本地计算机上运行迁移时发生。在我的 docker-compose 堆栈和 Vagrant 框中按预期完成。所有版本都是相同的。为什么这只会发生在我的 Mac 上?

【问题讨论】:

  • 从 ini 中删除了 xdebug.scream = 1,现在又可以工作了。

标签: laravel eloquent


【解决方案1】:

解决方法我在互联网上找到了它

Schema::table('table', function (Blueprint $table) {
    \DB::statement("ALTER TABLE table_name
CHANGE COLUMN old_column_name new_column_name data_type;");
});

我希望这会有所帮助。

参考文献

  1. Failed to rename a column in a migration
  2. Rename a column in MySQL

【讨论】:

    【解决方案2】:

    好像在v2.7中解决了[bug] Don't skip column options. #3089

    2.7 breaks renaming columns in mysql 5.7 #3091

    使用composer update doctrine/dbal升级包版本。

    【讨论】:

    • 成功了,谢谢!奇怪的是我当地的教义是如何失败的,但流浪者/码头工人却不是???相同的代码库???
    • 是 xdebug.scream = 1 搞砸了。我禁用了 xdebug 来运行上述更新,它开始工作,我重新启用它来运行一些调试,它停止了。
    猜你喜欢
    • 2017-07-11
    • 2016-02-16
    • 2019-01-27
    • 1970-01-01
    • 2015-07-22
    • 2020-05-02
    • 2016-04-06
    • 2014-12-23
    相关资源
    最近更新 更多