mysql - Laravel 5.5 - 迁移不起作用

标签 mysql laravel migration database-migration

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

In Connection.php line 664:

SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'to_date' (SQL: create table transactions (id
int unsigned not null auto_increment primary key, 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)

In Connection.php line 458: SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for '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 上运行?

最佳答案

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

关于mysql - Laravel 5.5 - 迁移不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48169317/

相关文章:

java - 如何确保 ResultSet 包含 "missing"观察的行

php - HTML 表单和 PHP 到 mySQL 的数据插入问题

php - Laravel Eloquent : How does it work? 基于动态模式元数据查找 = 性能?

mysql - 按月分组在 laravel Controller 中产生错误

mysql - 在 MySQL 中等同于 MS SQL 作业?

java - 取消委托(delegate)方法

php - 如何在我的数据库中将类别 ID 格式化为字符串

php - 有什么方法可以优化我的解决方案以获得更快、更优雅的方法吗?

backbone.js - 拉拉维尔。如何在 Backbone 中获取/传递登录用户 ID

php - Laravel 迁移 : 2 different tables with the same blueprint/structure