I use php artisan migrate:rollback
in terminal then error message bellow
H:\wamp_server\www\cms>php artisan migrate:rollback
[Illuminate\Database\QueryException] SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'is_admin' (SQL: alter table
posts
addis_admin
int not null)[PDOException] SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'is_admin'
migration code below
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddIsAdminColumnToPostsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('posts', function (Blueprint $table) {
//
$table->integer('is_admin')->unsigned();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('posts', function (Blueprint $table) {
//
$table->integer('is_admin');
});
}
}
your code is wrong, you are adding the column in the down function as well, see code below to fix:
public function down()
{
//
Schema::table('posts', function (Blueprint $table) {
$table->dropColumn('is_admin');
});
}
Laravel doc, showing this: https://laravel.com/docs/5.4/migrations#dropping-columns
I had same problem, Column already exists: Duplicate column name 'created_at'
I think it was due to
$table->timepstamps('dob');
my previous code
public function up()
{
Schema::create('authors', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->timestamps('dob');
$table->timestamps();
});
}
when I remove 's' form timestamp, like
$table->timestamp('dob');
It works fine for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With