您的位置:首页 > 编程语言 > PHP开发

laravel迁移文件一次删除创建字段报错

2018-03-08 22:07 549 查看
需求:通过写迁移文件更新user表中 topic 字段类型,从原来的varchar到json。
因为无法直接修改成json数据类型,只能采用先删除在创建的方式。
迁移文件代码如下:<?php

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

class CreateUserTable extends Migration{
/**
* 运行迁移
*
* @return void
*/
public function up()
{
Schema::create('user', function (Blueprint $table) {
if (Schema::hasColumn('topic')) {
    $table->dropColumn('topic');
}
$table->json('topic')->comment('主题');
});
}

/**
* 撤销迁移
*
* @return void
*/
public function down()
{
//
}
}执行迁移文件报错,提示topic这个字段已经存在。 
但是很显然上面已经删除了,但是 删除创建分开两次执行,一切正常。
猜想:可能是迁移文件执行类型与实务,一起提交才成功。后续有机会验证
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: