nurdaulet-shamilov

Apr 16th, 2019 12:57 PM

I am getting this error: Illuminate\Database\QueryException : SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'chatter_category_id' (SQL: alter table chatter_discussion add chatter_category_id int unsigned not null, add user_id bigint unsigned not null)

My Migration file is this
			
			Schema::table('chatter_discussion', function (Blueprint $table) {
        $table->integer('chatter_category_id')->unsigned()->index();
        $table->foreign('chatter_category_id')->references('id')->on('chatter_categories')
                    ->onDelete('cascade')
                    ->onUpdate('cascade');
        $table->bigInteger('user_id')->unsigned()->index();
        $table->foreign('user_id')->references('id')->on('users')
                    ->onDelete('cascade')
                    ->onUpdate('cascade');
    });
    Schema::table('chatter_post', function (Blueprint $table) {
        $table->integer('chatter_discussion_id')->unsigned()->index();
        $table->foreign('chatter_discussion_id')->references('id')->on('chatter_discussion')
                    ->onDelete('cascade')
                    ->onUpdate('cascade');
        $table->bigInteger('user_id')->unsigned()->index();
        $table->foreign('user_id')->references('id')->on('users')
                    ->onDelete('cascade')
                    ->onUpdate('cascade');
    });
bobbyiliev

Dec 24th, 2022 11:27 PM

Hi there,

I am following up on some of the old unanswered questions on the site.

As a remark, Chatter is no longer maintained. But in general if you get that error, it's possible that you have already run a migration that adds this column, or that the column was created manually in the database. In either case, you will need to either modify your migration to skip adding this column, or modify the existing column in the table to match the specifications in your migration (e.g. change its data type or add a foreign key constraint).