加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php – laravel migrate:回滚错误

发布时间:2020-12-14 19:35:14 所属栏目:大数据 来源:网络整理
导读:Laravel版本5.1.43(LTS) 我使用php artisan migrate:在终端回滚然后返回错误消息.但数据库已更改.然后我再次重新输入此命令,没有错误消息. 任何人都可以帮我解决这个问题吗? [IlluminateDatabaseQueryException] SQLSTATE[42000]: Syntax error or acces
Laravel版本5.1.43(LTS)

我使用php artisan migrate:在终端回滚然后返回错误消息.但数据库已更改.然后我再次重新输入此命令,没有错误消息.

任何人都可以帮我解决这个问题吗?

[IlluminateDatabaseQueryException]
SQLSTATE[42000]: Syntax error or access violation: 1091 Can’t DROP’user_id’; check that column/key exists (SQL: alter table crm_user drop index user_id)

[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1091 Can’t DROP ‘user_id’; check that column/key exists

我的迁移代码

public function down()
{
    if (Schema::hasColumn('crm_user','user_id')) {
        Schema::table('crm_user',function (Blueprint $table) {
            $table->dropColumn('user_id');
            $table->dropIndex('user_id');
        });
    }
}

解决方法

删除列时会自动删除索引.因此,当您尝试单独删除索引时,您会收到不存在的错误.

因此,要么交换订单,要先删除索引:

$table->dropIndex('user_id');
$table->dropColumn('user_id');

或者只是删除列,不要担心索引.

从MySQL手册:

If columns are dropped from a table,the columns are also removed from any index of which they are a part. If all columns that make up an index are dropped,the index is dropped as well.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读