【问题标题】:Laravel can't add new column to tableLaravel 无法在表格中添加新列
【发布时间】:2016-06-26 21:23:22
【问题描述】:

我想将新的枚举列 status 添加到 customers 表中。但是当我尝试运行迁移时,我得到了这个错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'status' in 'where clause' (SQL: select * from `customers` where `customers`.`deleted_at` is null and `status` = 1)  

  [PDOException]                                                                     
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'status' in 'where clause'  

迁移:

 public function up()
{
    Schema::table('customers', function (Blueprint $table) {
        $enum = [
            'activated' => 1,
            'deactivated' => 0
        ];
        $table->enum('status', $enum);
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('customers', function (Blueprint $table) {
        $table->dropColumn('status');
    });
}

【问题讨论】:

  • 该错误不是迁移代码引起的。
  • 该错误不是由此特定迁移引起的。也许您的迁移以错误的顺序运行,而另一个依赖于这个迁移,或者您的启动代码中的某些东西在迁移实际运行之前运行了该查询。

标签: php laravel laravel-migrations


【解决方案1】:

你的枚举值不应该是关联数组

$enum = ["activated","deactivated"];

【讨论】:

    猜你喜欢
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    • 2019-10-15
    • 2012-12-02
    • 2021-04-01
    • 2018-11-18
    • 1970-01-01
    • 2012-02-24
    相关资源
    最近更新 更多