这是我的迁移表
<?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 collate 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/