2021年5月1日星期六

Datatype mismatch on Boolean?

Something strange is happening, I have been seeding my project with some data for over 2 months already and suddenly today I couldn't seed them. So I went over to the test file and it's the same thing.

In migration, the column is

$table->boolean('is_visible')->default(true);  

In factory

'is_visible' => true  

In my test, it throws the query exception when i do

EmploymentType::factory()->create();  

This is the error

Illuminate\Database\QueryException : SQLSTATE[42804]: Datatype mismatch: 7 ERROR:  column "is_visible" is of type boolean but expression is of type integer  LINE 1: ...visible", "updated_at", "created_at") values (\$1, \$2, \$3, \$4...                                                               ^  HINT:  You will need to rewrite or cast the expression. (SQL: insert into "employment_types" ("name", "is_visible", "updated_at", "created_at") values (FULL-TIME, 1, 2021-05-01 01:19:05.980494, 2021-05-01 01:19:05.980494) returning "id")  

I can see that the values that is inserting is 1 - an integer but previously it was true. I have no idea how to fix this as all the other tables that have boolean like this is having the same errors. The only difference I did was upgrade PHP 7.4.16 to 7.4.18

Currently on:

Database - Postgres 13

Laravel Framework 8.34.0

Update:

Test with 'true' or '1' works but not true or 1 - why does this happen? Need some advice.

https://stackoverflow.com/questions/67342998/datatype-mismatch-on-boolean May 01, 2021 at 12:51PM

没有评论:

发表评论