0
votes

i am trying to migrate a file in laravel 5. i have already created a users table and successfully migrated it, but i get this error

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' alre ady exists (SQL: create table users (id int unsigned not null auto_incr ement primary key, name varchar(191) not null, email varchar(191) not n ull, password varchar(191) not null, remember_token varchar(100) null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci)

database\migrations\2018_01_22_091142_create_authors_table.php(file i am trying to migrate. database\migrations\2018_01_20_085218_create_users_table.php(file already migrated) thanks in advance

1
the error is self-explanatory , you are trying to create an already created tablehassan
php artisan migrate:reset .run this before php artisan migrateNanThiyagan

1 Answers

0
votes

The error is self-explanatory , you are trying to create an already created table.

you need to drop your table, in your Down method drop your table.

ONLY WHEN YOU ARE WRITING A MIGRATION TO CREATE NEW TABLES

public function down()
{
    Schema::dropIfExists('users');
}

also you can check for tables existence using hasTable method, to prevent creating the already created tables

if (!Schema::hasTable('users'))
{
    // create the new table
}