When i migrate my tables into db, it gives this error
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (SQL: create table
users
(id
int unsigned not null auto_increment primary key,body
longtext not null,url
varchar(255) null,user_id
int unsigned not null,commentable_id
int unsigned not null,commentable_type
varchar(191) not null,created_a t
timestamp null,updated_at
timestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci) In Connection.php line 449: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if(!Schema::hasTable('users')){
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table-> string('name');
$table-> string('email')->unique();
$table-> string('password');
$table->rememberToken();
$table->timestamps();
});
}
Schema::table('users', function(Blueprint $table){
$table -> string('first_name') -> nullabel();
$table -> string('middle_name') -> nullabel();
$table -> string('last_name') -> nullabel();
$table -> string('city') -> nullabel();
$table -> integer('role') -> unsigned();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
I dropped all the tables from database then i tried but same error given
php artisan migrate:fresh
– Farhad Misirli.env
file and see if the database name is what it should be. – Rouhollah Mazarei