Laravel 5.5 Error Base table or view already exists: 1050 Table 'users' already exists

半城伤御伤魂 提交于 2019-11-26 17:48:32

问题


Specifications:

  • Laravel Version: 5.5.3
  • PHP Version: 7.1
  • Database Driver & Version: MariaDB 10.1.26

Description:

C:/Users/user/code/blog/>php artisan migrate

[Illuminate\Database\QueryException]
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (SQL: create table users (id int unsigned not null aut
o_increment primary key, name varchar(255) not null, email varchar(255) not null, password varchar(255) not null, remember_token varchar
(100) null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci engine = InnoDB R
OW_FORMAT=DYNAMIC)

[PDOException]
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists

Steps To Reproduce:

 C:/Users/user/code/blog/>laravel new website

 C:/Users/user/code/blog/>php artisan make:migration create_lists_table --create=lists

 C:/Users/user/code/blog/>php artisan migrate

Problem

It Creates users table and give error but not creating lists table


回答1:


Here are the steps I took to solve the same issue:

  1. In the console I wrote php artisan tinker

  2. Then, again in the console, Schema::drop('users')

  3. At the end php artisan migrate and it all worked.




回答2:


I Solved My Problem Myself by Changing My create_users_table.php

<?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()
    {
        Schema::dropIfExists('users');
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

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



回答3:


Here are the steps I took to solve the same issue:

  1. php artisan make:migration create_tableName_table --create=tableName.

  2. php artisan migrate.

  3. appear error,you can drop all file in migration and all table in database.

  4. create new table as 1.

  5. finish. okay.




回答4:


Following command solved my problem:

 1. php artisan tinker
 2. Schema::drop('your_table_name')
 3. php artisan migrate



回答5:


I have different solution, i delete migration table, here my solution

<?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()
{
    Schema::dropIfExists('migration');
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
    });
}

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



回答6:


just delete those columns first from database. and run composer update . and then finally run php artisan migrate it would solve your problem. the simplest solution for your problem.




回答7:


There are two possible solutions for this as mentioned on this link:

https://www.codespeaker.com/laravel-framework/solutions-for-common-errors-on-artisan-commands/

First is rollback

php artisan migrate:rollback

Second is dropping of tables.




回答8:


The simple way to solve this problem is run the following command

php artisan migrate:fresh




回答9:


Solution:

  1. Go on database -> phpmyadmin if you are on localhost
  2. Delete everything on database that you created
  3. On cmd run php artisan migrate


来源:https://stackoverflow.com/questions/46129270/laravel-5-5-error-base-table-or-view-already-exists-1050-table-users-already

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!