【问题标题】:Why php migration fails on change table column type to string from numeric为什么 php 迁移在将表列类型从数字更改为字符串时失败
【发布时间】:2020-08-19 01:10:05
【问题描述】:

我是 PHP 和 laravel 平台的新手,在运行迁移任务以将表列类型从数字更改为字符串时需要您的帮助来解决 PDOException。

...
public function up()
{
    Schema::table('BuildTable', function (Blueprint $table) {
       $table->string('snapshot_id')->change();
    });

}
....

在运行迁移任务时获取 PDOException

Doctrine\DBAL\Driver\PDOException::("SQLSTATE[0A000]: Feature not supported: 7 ERROR:  unimplemented: type conversion from INT8 to VARCHAR(255) requires overwriting existing values which is not yet implemented
HINT:  You have attempted to use a feature that is not yet implemented.

现有的表结构是使用

创建的
      Schema::create(
        $this->tablename,
        function (Blueprint $table) {
            $table->increments('id');
            $table->integer('account_id')->unsigned();
            $table->integer('snapshot_id')->unsigned();
            $table->timestamps(6);
            $table->softDeletes('deleted_at', 6)->default(null);
        }
    );

现有的表已经有snapshot_id中的数据

php 版本是 7.3.20 运行在 linux mint 操作系统,数据库 - cockroachDB

【问题讨论】:

  • 这能回答你的问题吗? How to change column data type in laravel 5.6?
  • 克里斯,细节没有解决问题,我得到“SQLSTATE[0A000]: Feature not supported: 7 ERROR: unimplemented: type conversion from INT8 to VARCHAR(255) requires覆盖现有值尚未实施
  • 我认为错误信息是不言自明的。您的表已经包含存储为 INT8 的数据,并且您要求引擎转换为 VARCHAR(255),但它不知道该怎么做。如果表中没有数据,情况会有所不同。你为什么要把看起来像外键的东西转换成字符串?
  • @sykez @Unflux 你是对的,这是一个与数据库相关的问题,因为我在工具中直接执行 SQL 时也遇到了类似的异常。我们正在使用 cockroachDB,它看起来像从 INT8 到 VARCHAR 的直接数据转换功能不适用于这个特定版本

标签: php laravel postgresql migration


【解决方案1】:

此功能将在今年晚些时候发布的 CockroachDB v20.2 中进行实验。

如果需要,您可以使用具有此功能的 alpha 版本 (v20.2.0-alpha.2) 进行测试。请参阅release notes。要使用它,您需要设置以下会话变量:SET enable_experimental_alter_column_type_general = true;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-18
    • 2015-08-02
    • 2021-02-04
    • 2019-09-18
    • 1970-01-01
    • 1970-01-01
    • 2020-06-24
    • 1970-01-01
    相关资源
    最近更新 更多