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

ledah's avatar
Level 1

Laravel RAW query with IGNORE doesn't work as expected

I have a project for travel agent where I need to insert date that support incomplete date. So there are 3 possible format:

  • YYYY-MM-DD
  • YYYY-MM-00
  • YYYY-00-00

00 means month or day is not set.

In my database (MariaDB v10.1.28) I can run this query and it sets the date as I wish:

UPDATE IGNORE schedule SET departure_date = "2019-00-00" WHERE id = "10" // result: 2019-00-00

I use IGNORE to bypass strict mode in config/database.php. In Laravel, when I tried to run this raw SQL query:

DB::update('UPDATE IGNORE schedule SET departure_date = ? WHERE id = ?', ['2019-00-00', '10']);  // result: 0000-00-00

said record will have its departure_date changed to 0000-00-00. Is this a bug? There is a workaround to use 3 tinyInt but changing structure might mess everything else up.

0 likes
6 replies
shez1983's avatar

are you changing FLIGHT column or DEPARTURE column.. as it stands it looks like your table is called departure and column flight which doesnt make sense to me.

1 like
ledah's avatar
Level 1

sorry for my bad choice of words. I've updated table and column name for better clarity

shez1983's avatar

no worries.. what happens if you actually hard code the date instead of using the ? syntax.

ledah's avatar
Level 1
DB::update(UPDATE IGNORE schedule SET departure_date = "2019-00-00" WHERE id = "13"');

like this? still same weird result, 0000-00-00

shez1983's avatar

can you post your column info (Ie how you are storing this in your db, ie show create statemnt)

ledah's avatar
Level 1

I create my table using Migration

Schema::create('schedule', function (Blueprint $table) {
    $table->increments('id');
    $table->date('departure_date')->nullable();
});

for creating new record I replace the 00 in date to 01, store it using Eloquent, then update the newly created record with actual incomplete date.

use Illuminate\Http\Request;
use App\Schedule; // model for table 'schedule'
...
public function update(Request $request)
{
    // validation here
    ....    
    $actualDate = $request->departure_date;
    ....
    // modifying the date then assign it to '$request'
    $request->departure_date = $modifiedDate;
    ....
    $schedule= new Schedule($request);
    $schedule->save();

    DB::update('UPDATE IGNORE schedule SET departure_date = ? WHERE id = ?', [$actualDate, $schedule->id]);
    // result: '0000-00-00'
}

I separate it because I want other column to be inserted in strict mode.

Please or to participate in this conversation.