【发布时间】:2020-11-10 07:43:37
【问题描述】:
我试图在 Postgres 和 Laravel 6.x 上将一列从字符串类型更改为整数。我试图通过这样的迁移来做到这一点:
public function up()
{
Schema::table('job_listings', function (Blueprint $table) {
$table->integer('company_id')->change();
});
}
当我运行此迁移时,我收到一个错误,该列无法自动转换为整数:
In Connection.php line 664:
SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column "company_id" cannot be cast automatically to type integer
HINT: You might need to specify "USING company_id::integer". (SQL: ALTER TABLE job_listings ALTER company_id TYPE INT)
In PDOStatement.php line 123:
SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column "company_id" cannot be cast automatically to type integer
HINT: You might need to specify "USING company_id::integer".
In PDOStatement.php line 121:
SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column "company_id" cannot be cast automatically to type integer
HINT: You might need to specify "USING company_id::integer".
PostgreSQL 中如何指定 USING 将该列从字符串类型更改为整数?
【问题讨论】:
标签: php laravel postgresql eloquent laravel-migrations