首页 文章

Laravel 5.5 - 迁移不起作用

提问于
浏览
0

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

在Connection.php第664行:SQLSTATE [42000]:语法错误或访问冲突:1067'to_date'的默认值无效(SQL:创建表事务(id int unsigned not null auto_increment主键,user_id int unsigned not null,vehicle_id int unsigned not null,from_date t imestamp not null,to_date timestamp not null,flight_number varchar(255)not null,created_at timestamp null,updated_at ti mestamp null)default character set utf8mb4 collate 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 回答

  • 2

    我找到了导致问题的原因,默认情况下在 laravel config database.php 文件中启用了严格模式,通过将模式设置为 'strict' => false ,就像在版本5.3中我能够运行迁移一样 .

相关问题