【发布时间】:2021-06-30 12:02:42
【问题描述】:
我想将字段从字符串转换为布尔值 试试这段代码:
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) {
//
});
}
但我得到了下面的错误
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".")
这是原始迁移:
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');
});
}
如何将此字段类型从整数更改为布尔值?
【问题讨论】:
-
请分享原始迁移
-
数据库类型是postgresql吗?这有帮助吗? stackoverflow.com/questions/41149554/…
-
是的,这项工作。谢谢。
标签: php laravel postgresql laravel-migrations