Laravel 5.5 - 迁移不起作用

时间:2018-01-09 13:30:57

标签: mysql laravel migration database-migration

我正在尝试运行一个在Laravel 5.2版本上完全正常运行的迁移,但是当我尝试在laravel 5.5上运行它时出现错误:

  

在Connection.php第664行:

     

SQLSTATE [42000]:语法错误或访问冲突:1067无效   ' to_date'的默认值(SQL:create table transactionsid
  int unsigned not null auto_increment主键,user_id int   unsigned not null,vehicle_id int unsigned not null,from_date t
  imestamp不为空,to_date时间戳不为空,flight_number   varchar(255)not null,created_at timestamp null,updated_at ti
  mestamp null)默认字符集utf8mb4 collat​​e   utf8mb4_unicode_ci)

     

在Connection.php第458行:                                                                                                     SQLSTATE [42000]:语法错误或访问冲突:1067无效   ' to_date'

的默认值

这是该表的迁移:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTransactionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('transactions', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned();
            $table->foreign('user_id')->references('id')->on('users');
            $table->integer('vehicle_id')->unsigned();
            $table->foreign('vehicle_id')->references('id')->on('vehicles');
            $table->timestamp('from_date');
            $table->timestamp('to_date');
            $table->string('flight_number');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('transactions');
    }
}

为什么在使用5.2版本时不能使用新版本的laravel?

1 个答案:

答案 0 :(得分:2)

我发现导致此问题的原因是, laravel 5.5 MySQL 严格模式已在 laravel config database.php文件中启用默认情况下,通过将模式设置为'strict' => false,就像在版本5.3中一样,我可以运行迁移。

相关问题