【问题标题】:Laravel 5.5 - migration not workingLaravel 5.5 - 迁移不起作用
【发布时间】:2018-06-18 13:18:45
【问题描述】:

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

在 Connection.php 第 664 行:

SQLSTATE[42000]:语法错误或访问冲突:1067 无效 'to_date' 的默认值(SQL:创建表 transactions (id
int unsigned not null auto_increment 主键,user_id int 无符号非空,vehicle_id int 无符号非空,from_date t
时间戳不为空,to_date 时间戳不为空,flight_number varchar(255) 不为空,created_at 时间戳为空,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');
    }
}

为什么新版本的 laravel 在 5.2 上工作时却不能工作?

【问题讨论】:

标签: mysql laravel migration database-migration


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2017-06-18
    • 1970-01-01
    • 2019-02-07
    • 2018-10-18
    • 2021-02-08
    • 2018-01-21
    相关资源
    最近更新 更多