【问题标题】:Laravel migrate.I want to remove a column and then add another column, but this is an errorLaravel 迁移。我想删除一列,然后添加另一列,但这是一个错误
【发布时间】:2021-09-01 22:43:36
【问题描述】:
Schema::table('cms_myterms', function (Blueprint $table) {
        $table->dropColumn('created_at');
        $table->timestamps();
    });

但这是错误的。

在 Connection.php 第 664 行:

SQLSTATE[42S21]: 列已存在: 1060 列名重复'created_at' (SQL: alter table cms_myterms add cre ated_at timestamp null, add updated_at timestamp null)

在 Exception.php 第 18 行:

SQLSTATE[42S21]: 列已经存在: 1060 Duplicate column name 'created_at'

在 PDOStatement.php 第 112 行:

SQLSTATE[42S21]: 列已经存在: 1060 Duplicate column name 'created_at'

【问题讨论】:

  • 在一次通话中,您不能删除并重新创建同一列。要么添加updated_at,要么使用不同的调用来删除和创建。

标签: laravel migrate


【解决方案1】:

您可以添加updated_at 列。

$this->timestamp('updated_at')->nullable();

【讨论】:

    猜你喜欢
    • 2018-06-28
    • 1970-01-01
    • 2011-04-09
    • 2020-03-08
    • 2017-12-18
    • 2018-01-30
    • 1970-01-01
    • 2020-05-19
    • 1970-01-01
    相关资源
    最近更新 更多