jeudi 2 juillet 2020

Laravel allowing null dates on Model::create() but not Model->update()

I have setup my Laravel migration to allow nullable dates for my StartTime and EndTime entries as such:

$table->dateTime( 'StartTime' )->nullable();
$table->dateTime( 'EndTime' )->nullable();

When I create a new entry through eloquent, it allows me to insert null values into my database successfully:

+----+-------+--------+-----------+---------+---------------------+
| Id | Name  | Active | StartTime | EndTime | created_at          |
+----+-------+--------+-----------+---------+---------------------+
|  1 | Test2 |      0 | NULL      | NULL    | 2020-07-02 22:01:22 |
+----+-------+--------+-----------+---------+---------------------+
1 row in set (0.00 sec)

However, when I later try and update my record using eloquent and still passing a null value for StartTime, it throws an error:

(22007) SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: 'null' for column 'StartTime' at row 1

Am I missing something here? I can't seem to find a solution to this anywhere.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire