I want to convert a field from string to boolean trying this code:
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->boolean('email_permission')->change();
$table->boolean('sms_permission')->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
//
});
}
but i got the error below
Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column
"email_permission" cannot be cast automatically to type boolean
HINT: You might need to specify "USING email_permission::boolean".")
this is original migration:
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('email_permission')->nullable()->default('0');
$table->string('sms_permission')->nullable()->default('0');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('email_permission');
$table->dropColumn('sms_permission');
});
}
how can i change this field type from integer to boolean ?