php - SQLSTATE[42S01] : Base table or view already exists or Base table or view already exists: 1050 Table

标签 php laravel-5.4

这是我的迁移表

    <?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserTable extends Migration
{

    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('role_id')->unsigned();
            $table->string('name');
            $table->string('email',50)->unique();
            $table->string('username');
            $table->string('password');
            $table->boolean('active');
            $table->rememberToken();
            $table->timestamps();

        });
    }

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

每当我尝试迁移时都会发生以下错误

*[照亮\数据库\QueryException] SQLSTATE[42S01]:基表或 View 已存在:1050 表“用户”已存在 ady 存在(SQL:创建表 users ( id int unsigned not null auto_incr ement 主键,role_id int 无符号非空,name varchar(191) 不 空,email varchar(50) 不为空,username varchar(191) 不为空,pas sword varchar(191) 不为空,active tinyint(1) 不为空,remember_token varchar(100) 空, created_at时间戳为空,updated_at时间戳 nu ll) 默认字符集utf8mb4 collat​​e utf8mb4_unicode_ci)

[PDO异常] SQLSTATE[42S01]:基表或 View 已存在:1050 表“用户”已存在 ady 存在*

请告诉我我该怎么办?我已经使用 migrate:reset 或 dumpautoload 或 rollback 没有任何反应。我花了很多时间编辑或删除这个用户文件并重新创建它。

最佳答案

尝试这样

   <?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserTable extends Migration
{

    public function up()
    {
        Schema::dropIfExists('users');
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('role_id')->unsigned();
            $table->string('name');
            $table->string('email',50)->unique();
            $table->string('username');
            $table->string('password');
            $table->boolean('active');
            $table->rememberToken();
            $table->timestamps();

        });
    }

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

关于php - SQLSTATE[42S01] : Base table or view already exists or Base table or view already exists: 1050 Table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44141475/

相关文章:

php - Laravel:大规模 updateOrCreate()

php - 无法让 WordPress 显示多站点中的所有类别

php - 查找可能的 URL 参数

php - 在 htaccess 中禁用 php 函数

php - MySQLi 多个准备语句

facebook-javascript-sdk - Facebook 从我在 Laravel 中的网站注销

Laravel 5.4 - 访问 Controller 方法内的静态方法

php - 将特定部分 div 转换为 pdf

javascript - 表单数据为空 - laravel 5.4

php - 非静态方法 Redis::get() 不能在 laravel 5.4 中静态调用?