Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LaraBABA's avatar

Migration failing for datetime

Hi all,

I have never experienced this in my previous migrations, I have this:

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('events', function (Blueprint $table) {
            $table->dateTime('active_to');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('events', function (Blueprint $table) {
            $table->dropColumn('active_to');
        });
    }
};

Locally the above command works on MariaDB 10.3

But on the remote (using 10.3.36-MariaDB) I am getting this:

 INFO  Running migrations.

  2022_07_21_130130_add_off_date_to_events_table ................ 30.00ms FAIL

   Illuminate\Database\QueryException

  SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '0000                                         -00-00 00:00:00' for column `xxxxxx_database`.`events`.`active_to` at ro                                         w 1 (SQL: alter table `events` add `active_to` datetime not null)

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:759
    755▕         // If an exception occurs when attempting to run a query, we'll                                          format the error
    756▕         // message to include the bindings with SQL, which will make th                                         is exception a
    757▕         // lot more helpful to the developer instead of just the databa                                         se's errors.
    758▕         catch (Exception $e) {
759▕             throw new QueryException(
    760▕                 $query, $this->prepareBindings($bindings), $e
    761▕             );
    762▕         }
    763▕     }

      +9 vendor frames
  10  database/migrations/2022_07_21_130130_add_off_date_to_events_table.php:18
      Illuminate\Support\Facades\Facade::__callStatic("table")

      +25 vendor frames
  36  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Cons                                         ole\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

Any idea what could cause this please?

Thank you

0 likes
4 replies
tykus's avatar
tykus
Best Answer
Level 104

Probably different sql_mode on the production database - you have NO_ZERO_DATE enabled in production probably.

1 like
LaraBABA's avatar

@tykus Quick question for you Tykus please, if NO_ZERO_DATE is enabled and you want to create a dateTime column, how would you do it please? Is the only choice to disable this setting? Thank you.

LaraBABA's avatar

@tykus oK, All I had to do is add ->nulled() to the column migration.

Please or to participate in this conversation.