'Laravel Migrate: "Column Already Exists" 1060 Duplicate Column Name

This is a fresh laravel app that I am using to learn. There is no current table as this would be a fresh/first time migration. Why is it giving me this error:

SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'title' (SQL: create table categories (id bigint unsigned not null auto_increment primary key, title varchar(255) not null, detail varchar(300) not null, image varchar(255) not null, title varchar(255) not null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

<?php

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

class CreateCategoriesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('categories', function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->string('detail', 300);
            $table->string('image');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('categories');
    }
}


Solution 1:[1]

If you have updated the original table migration for the categories table then you need to either add the parameter fresh to your php artisan migrate command like this:

php artisan migrate:refresh

Be aware that that will remove all your data from the database.

And if you don't like that method then add change() add the end of detail field:

$table->string('detail', 300)->change();

Solution 2:[2]

Fixed. For some reason when all I had to do was change 'detail' from string to text like this:

$table->string('detail', 300)

to

$table->text('detail', 300)

I don't understand why this worked, but it did.

Solution 3:[3]

I had a similar problem. You should just look at the error keenly. It says duplicate column name 'title'. You certainly tried to create this column twice, remove one and retry. It should work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hedayatullah Sarwary
Solution 2 All_Semicolons
Solution 3 Johan Tchassem