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

前端 未结 15 1307
温柔的废话
温柔的废话 2020-11-30 10:22

Specifications:

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

15条回答
  •  执念已碎
    2020-11-30 11:00

    Agree with Nitesh's answer but I think that's not the best practice to drop the table everytime for no reason. We could also use simple "if" check with condition Schema::hasTable('users') according to the docs. So we can use it as:

    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');
        }
    }
    

    This solution will also be feasible in the scenario when you will already have a table and need some modification then you will be able to do anything in the else statement as well.

提交回复
热议问题