迁移刷新错误 [英] error with migrate refresh

查看:127
本文介绍了迁移刷新错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试运行时出现此错误:php artisan migration:refresh:

I am getting this error when trying to run: php artisan migrate:refresh:

Rolled back: 2016_02_16_114444_create_posts_table
Rolled back: 2016_01_20_234538_expectations
Rolled back: 2016_01_20_200616_expectation_profile
Rolled back: 2015_12_22_111958_create_profiles_table
Rolled back: 2014_10_12_100000_create_password_resets_table
Rolled back: 2014_10_12_000000_create_users_table


  [Illuminate\Database\QueryException]                                          
  SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'follower  
  _id' (SQL: alter table `follower_followee` add `follower_id` int unsigned no  
  t null, add `followee_id` int unsigned not null)                              

  [PDOException]                                                                
  SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'follower  
  _id'

这是错误所指的迁移:

<?php

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

class FollowerFollowee extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('follower_followee', function (Blueprint $table) 
        {
            $table->integer('follower_id')->unsigned(); // follower id number,must be positive.
            $table->integer('followee_id')->unsigned(); // followee id number,must be positive.
            $table->foreign('follower_id')->references('id')->on('users')->onDelete('cascade');
            //The 'follower_id' column references to the 'id' column in a 'users' table.
            //When a user is deleted in the parent column ('follower_id'), then also the user in 'id' ('users') is deleted. 
            $table->foreign('followee_id')->references('id')->on('users')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()

{
    Schema::dropIfExists('follower_followee');
    }
}

当尝试运行时:composer dump-autoload-它仅返回以下内容:

when trying to run : composer dump-autoload - it returns only this:

Generating autoload files

老实说,我无法确定重复出现在哪里.任何帮助都将很可爱.

I honestly can't identify where's that duplication appears. Any help would be lovely.

谢谢.

推荐答案

我将错误(在终端中)中提到的表的down方法更改为:

I have changed the tables' down method mentioned in the error (in the terminal) to this:

public function down()
{
    DB::statement('SET FOREIGN_KEY_CHECKS = 0');
    Schema::dropIfExists('follower_followee');
    DB::statement('SET FOREIGN_KEY_CHECKS = 1');
}
}

这样,我可以删除父表而不会出现外键错误.

With this I can delete parent tables without errors for foreign keys.

仅对表进行了设置.然后从db中手动删除我所有的表,然后运行php artisan migration和php artisan migration:refresh,没有任何错误. 感谢您尝试提供帮助的人!

did it for the tables only. then removed manually all my tables from db and then ran php artisan migrate and php artisan migrate:refresh without any errors. Thanks for whoever tried to help!

这篇关于迁移刷新错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆