so i want to php artisan migrate:fresh but i get this error
Base table or view already exists: 1050 Table 'roles' already exists
even if i drop the database from phpmyadmin, clean the cache and create the database again it still show the same message the migration for the table rows is the following one:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateRolesTable extends Migration
{
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->tinyInteger('status');
});
}
public function down()
{
Schema::dropIfExists('roles');
}
}
the full error displayed:
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'roles' already exists (SQL: create table
roles(idbigint unsigned not null auto_increment primary key,namevarchar(255) not null,guard_namevarchar(255) not null,created_attimestamp null,updated_attimestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
Why is that? and what can or should I do?
CodePudding user response:
First drop roles table using this code Schema::dropIfExists('roles'); then create.
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateRolesTable extends Migration
{
public function up()
{
Schema::dropIfExists('roles'); //added
Schema::create('roles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->tinyInteger('status');
});
}
public function down()
{
Schema::dropIfExists('roles');
}
}
CodePudding user response:
If it already exists before you did artisan migrate it will of course say this. Did you do migrate and it broke half way? You can reset it or just delete the table and try again (if you are in local dev and can delete it).
php artisan migrate:reset
