ErrorException:PHP工匠迁移期间将数组转换为字符串:fresh

时间:2019-05-01 12:42:04

标签: laravel laravel-migrations

尝试将列设置为dateTime类型,并默认将其设置为当前时间和日期。但是,我一直得到标题中提到的错误...

该问题与“ dateAccepted”字段有关,“ dateSubmitted”也可能也存在此问题,但是我还没有尝试过。

我使用的数据类型错误吗?或只是编码错误..?欢迎所有建议。 (该网站的P.S是新的,敬请谅解)

public function up()
{
    Schema::create('adoption_requests', function (Blueprint $table) {
        $table->increments('id');
        $table->bigInteger('userid')->unsigned();
        $table->bigInteger('animalID')->unsigned();
        $table->date('dateSubmitted');
        $table->dateTime('dateAccepted')->default(getdate())->nullable();
        $table->date('requestAccepted');
        $table->date('staffID');
        $table->timestamps();
        //$table->boolean('$adoptionStatus')->default(0);
        $table->foreign('userid')->references('id')->on('users');
        $table->foreign('animalID')->references('id')->on('animals');

    });
}
    ErrorException  : Array to string conversion

  at C:\xampp\htdocs\AAS\vendor\laravel\framework\src\Illuminate\Database\Schema\Grammars\Grammar.php:248
    244|         }
    245|
    246|         return is_bool($value)
    247|                     ? "'".(int) $value."'"
  > 248|                     : "'".(string) $value."'";
    249|     }
    250|
    251|     /**
    252|      * Create an empty Doctrine DBAL TableDiff from the Blueprint.

  Exception trace:

  1   Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Array to string conversion", "C:\xampp\htdocs\AAS\vendor\laravel\framework\src\Illuminate\Database\Schema\Grammars\Grammar.php", [])
      C:\xampp\htdocs\AAS\vendor\laravel\framework\src\Illuminate\Database\Schema\Grammars\Grammar.php:248

  2   Illuminate\Database\Schema\Grammars\Grammar::getDefaultValue()
      C:\xampp\htdocs\AAS\vendor\laravel\framework\src\Illuminate\Database\Schema\Grammars\MySqlGrammar.php:946

  Please use the argument -v to see more details.

1 个答案:

答案 0 :(得分:0)

$table->dateTime('dateAccepted')->default(DB::raw('CURRENT_TIMESTAMP'));

这可能会帮助

修改

说明:

函数gettime()重新调整数组。因此,您无法在datetime列中存储值的数组。您将需要一个datetime

不同于原始答案的另一种方法是

$table->dateTime('dateAccepted')->default(now()->toDateTimeString());