[8.x] Primitive castes are not handled #34387
Replies: 2 comments
-
Indeed, seems you're a victim of Laravel never performed casts on primitive types for setting them (only reading) and MySQL non-strict behaviour silently accepting invalid values. I made the move from MySQL to PgSql years ago; interestingly I never noticed the absence of this; maybe I just got lucky. OTOH I'm also not developing project without static anlayzers and ide-helper, so nowadays I can't make that mistake even with the actual behviour missing. Curious. Wonder what's the reason for this. |
Beta Was this translation helpful? Give feedback.
-
A value is given to the input, validated according to the integer rule - the validator passes it, then everything is correct. MySQL casts itself to the desired type, but in the case of Postgres this did not happen. I started looking for the reason and saw the lack of processing of primitive types. I had to create a custom cast and assign all integer fields in the project. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Description:
I am transferring an application from a MySQL 8 database to PostgreSQL 12.4 and I get this error:
// Model casts:

I checked the data before inserting and I see that the field did not pass the cast:

The problem is that primitive variables are not cast before being written to the database:
https://github.com/laravel/framework/blob/8.x/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php#L636-L672
There are two solutions:
I consider the first as an overhead on primitive types, and generally keep quiet about the second.
Beta Was this translation helpful? Give feedback.
All reactions