Laravel迁移,hasColumn方法失败

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Laravel迁移,hasColumn方法失败相关的知识,希望对你有一定的参考价值。

我正在使用laravel 5.2版本和php 7.1。我正在尝试从我的laravel项目中迁移文件,其中我有代码来检查列的存在,如下所示 -

if (!Schema::hasColumn('table1', 'column1')) {
    // Add column1
}

我知道代码非常好,并且在设置相同代码时已经多次使用了。但现在我在单独的机器上尝试这个并且失败并出现错误 -

[ErrorException] 未定义的属性:stdClass :: $ column_name

如果我从代码中删除hasColumn检查,我可以摆脱这个错误,但这是我在整个代码中编写的内容,并且不能仅为了运行迁移而修改每个迁移。

对此有任何帮助非常感谢。

堆栈跟踪:

[ErrorException] 未定义的属性:stdClass :: $ column_name

异常跟踪:()at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/mysqlProcessor.php:18 Illuminate Foundation Bootstrap HandleExceptions-> handleError() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/MySqlProcessor.php:18 Illuminate Database Query Processors MySqlProcessor-> Illuminate Database Query 处理器{closure}()at n / a:n / a array_map()at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/MySqlProcessor.php:21在/private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Schema/MySqlBuilder.php:40 Illuminate Database Schema中照亮 Database Query Processors MySqlProcessor-> processColumnListing() MySqlBuilder-> getColumnListing()at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:69 Illuminate Database Schema Builder-> hasColumn()在/private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:217 Illuminate Support Facades Facade :: __ callStatic()at / private / var / www / html / whitelabel_eb / database / migrations / 2017_07_28_053158_add_columns_to_project_configurations_table.php:16 AddColumnsToProjectConfigurationsTable - > {closure}()at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint.php :69 Illuminate Database Schema Blueprint - > __ construct()at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:207 Illuminate Database Schema Builder-> createBlueprint()at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:116 Illuminate Database Schema Builder-> table() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:217 Illuminate Support Facades Facade :: __ callStatic()at / private / var / ww w / html / whitelabel_eb / database / migrations / 2017_07_28_053158_add_columns_to_project_configurations_table.php:103 AddColumnsToProjectConfigurationsTable-> up()at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php :135 Illuminate Database Migrations Migrator-> runUp()at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:112 Illuminate Database Migrations Migrator-> runMigrationList()at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:85 Illuminate Database Migrations Migrator-> run() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:74 Illuminate Database Console Migrations MigrateCommand-> fire()at n / a:不适用于/private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Container/Container.php:507的call_user_func_array()Illuminat e Container Container-> call()at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Console/Command.php:150 Illuminate Console Command-> execute()at / private / var / / / / / / / / / / / / / / / / / / / / / / / / / / / / / vendor / laravel / framework / src / Illuminate / Console / Command.php:136 Illuminate Console Command-> run()at /private/var/www/html/whitelabel_eb/vendor/symfony/console/Application.php:840 Symfony Component Console Application-> doRunCommand()at /private/var/www/html/whitelabel_eb/vendor/symfony/console/Application.php:190 Symfony Component Console Application-> doRun()at / private /var/www/html/whitelabel_eb/vendor/symfony/console/Application.php:114 Symfony Component Console Application-> run()at / private / var / www / html / whitelabel_eb / vendor / laravel / framework / src / Illuminate / Foundation / Console / Kernel.php:107 Illuminate Foundation Console Kernel-> handle()at / p rivate /无功/网络/ HTML / whitelabel_eb /人员:35

答案

看看这个问题,可能https://github.com/laravel/framework/pull/21037解决了这个问题,但是这个改变是为了Laravel 5.5。 Laravel 5.2不再受支持,因此您可以尝试在需要时使用自己的fork来修复此问题 - 您可以使用Composer VCS功能。

当然升级到最新版本可能是一个好主意(很多问题在以后的版本中得到解决),但假设您的应用程序很复杂并且没有合适的测试,那么它可能会有风险。

以上是关于Laravel迁移,hasColumn方法失败的主要内容,如果未能解决你的问题,请参考以下文章

Laravel 迁移重置失败

:完整性约束违规:1452 无法添加或更新子行:laravel 迁移中的外键约束失败

Laravel 迁移失败

Laravel 工匠迁移失败

Php工匠迁移失败Laravel [重复]

Laravel 5.4 迁移 ENUM 在 MySQL 中失败