1
votes

I'm trying to change column type from integer to boolean.

I've created a migration with following

$table->integer('has_varients')->default(0)->comment('1:yes, 0:no');

Now I'm creating another migration to alter datatype

$table->boolean('has_varients')->nullable()->change();

When running php artisan migrate, I'm getting following error,

SQLSTATE[42804]: Datatype mismatch: 7 ERROR:  column "has_varients" cannot be cast automatically to type boolean
HINT:  You might need to specify "USING has_varients::boolean". (SQL: ALTER TABLE products ALTER has_varients TYPE BOOLEAN)

I'm using PostgreSQL.

1
If column already contains data then, laravel has no idea how to convert it to boolean, as per my knowledge it wont be straight forward to change it like this. - Prashant Deshmukh.....

1 Answers

0
votes

I think you need to explicitly tell the SQL statement how to convert it.

Postgres itself wouldn't know what false or true should be represented in DECIMAL(12,4).