【问题标题】:How can I update the data type of a column inside a table in Laravel?如何更新 Laravel 表中列的数据类型?
【发布时间】:2021-02-14 00:14:14
【问题描述】:

我正在尝试更新我的列的数据类型,因为它需要加密。我为此创建了一个新的迁移并尝试了这个:

public function up()
{
    Schema::table('users', function(Blueprint $table) {
        $table->dropColumn(['team', 'service_number']);
        $table->string('team', 188);
        $table->string('service_number', 188);
    });
}

但是,我收到此错误:

SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'team' (SQL: alter table `users` add `team` varchar(1024) not null, add `service_number` varchar(1024) not null)

如何更新表中列的数据类型?

【问题讨论】:

  • Tru 使用两个模式,第一个删除,第二个创建
  • 这是有道理的。有没有更好的方法来做到这一点,还是因为这不是交易而受到限制? @porloscerrosΨ
  • 您当前要更改的这些字段是什么类型?
  • 整数@lagbox

标签: php laravel migration database-migration


【解决方案1】:

我认为您需要这样做(尽管这不会删除列):

    $table->string('team', 188)->change();
    $table->string('service_number', 188)->change();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-16
    • 1970-01-01
    • 2012-06-12
    • 2012-02-20
    • 2021-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多