SQLSTATE [42S01]:基本表或视图已存在或基本表或视图已存在:1050表 [英] SQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Table

查看:1114
本文介绍了SQLSTATE [42S01]:基本表或视图已存在或基本表或视图已存在:1050表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的迁移表

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

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

when ever i try to migrate the following error occur

* [Illuminate \ Database \ QueryException] SQLSTATE [42S01]:基本表或视图已经存在:1050表'users'alre ady存在(SQL:创建表users(id int unsigned not null auto_incr 水泥主键,role_id int unsigned不为null,name varchar(191)不为 null,email varchar(50)不为空,username varchar(191)不为空,pas sword varchar(191)不为空,active tinyint(1)不为空,remember_token varchar(100)为空,created_at时间戳为null,updated_at时间戳为nu ll)默认字符集utf8mb4整理utf8mb4_unicode_ci)

*[Illuminate\Database\QueryException] 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, role_id int unsigned not null, name varchar(191) not null, email varchar(50) not null, username varchar(191) not null, pas sword varchar(191) not null, active tinyint(1) not null, remember_token varchar(100) null, created_at timestamp null, updated_at timestamp nu ll) default character set utf8mb4 collate utf8mb4_unicode_ci)

[PDOException] SQLSTATE [42S01]:基本表或视图已存在:1050表'users'all 阿迪存在*

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

请告诉我该怎么办?我已经使用过migration:reset或dumpautoload或rollback没有任何反应.很多时间我都编辑或删除了这个usersfile并重新创建了它.

推荐答案

尝试这样

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

这篇关于SQLSTATE [42S01]:基本表或视图已存在或基本表或视图已存在:1050表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆