2 weeks ago by drax7

I am trying to run a migration that works perfectly fine on Laravel 5.2 version, but when I try to run it on the laravel 5.5 I get an error:

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'

This it the migration for that table:

<?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');
    }
}

Why is it not working with the new version of laravel when it is working with the 5.2?

1 week ago by Yoshi Mannaert

Hey @drax7, from what I've found this seems like it might be an error on your database side. Are you using MySQL? Then try to change it to $table->timestamp('to_date')->nullable(); and see if that helps.

Otherwise you could change your database config file to set 'strict' => false

Sign in or create an account to reply to this topic.