gpt4 book ai didi

php - 更新现有的列属性 - Laravel 5 迁移

转载 作者:行者123 更新时间:2023-12-04 16:45:29 25 4
gpt4 key购买 nike

我有
一个名为 cpe_mac 的现有列.我通过这样的迁移创建了它:

$table->string('cpe_mac')->default(NULL)->nullable();

我想要
我想加这个 ->unique()到该列,而不必 放下并重新添加 .

我试过了
$table->string('cpe_mac')->unique();

迁移文件
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AlterCaptivePortalTable212017 extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('captive_portals', function (Blueprint $table) {
$table->string('cpe_mac')->unique();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('captive_portals', function (Blueprint $table) {
$table->string('cpe_mac')->default(NULL)->nullable();
});
}
}

我一直
得到
SQLSTATE[42701]: Duplicate column: 7 ERROR:  column "cpe_mac" of relation "captive_portals" already exists
有没有办法在不必删除现有列的情况下实现这一目标?我有很多无法删除的客户端数据。

最佳答案

Schema::table('users', function (Blueprint $table) {
$table->string('cpe_mac')->unique()->change();
});

https://laravel.com/docs/5.0/schema#changing-columns

关于php - 更新现有的列属性 - Laravel 5 迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41987609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com