Laravel5.4 错误,SQLSTATE[42S01]:基表或视图已存在:1050 表'users'已存在



>规格:

拉拉维尔版本:5.4 PHP 版本: 7.0.9 作曲家版本 1.9.0 闽能

描述:

在连接中.php第 647 行:

SQLSTATE[42S01]:基表或视图已经存在:1050 表"users"已经存在(SQL:创建表users( idint unsigned not null auto_increment主键,namevarchar(255) 不为空,emailvarchar(255) 不为空,passwordvarchar(255) 不为空,remember_tokenvarchar(100) 为空,created_at时间戳为空,updated_attim Estamp 空) 默认字符集 UTF8MB4 整理 utf8mb4_unicode_ci)

在连接中.php第 449 行:

SQLSTATE[42S01]:基表或视图已存在:1050 表"用户"已存在

问题:我创建了用户和产品的模型和表格。它成功地创建了迁移和表,但未能在phpmyadmin sql上迁移。

我尝试的步骤:我已经删除了所有数据库并重新创建了它,但它仍然给出错误。 我也使用过修补,但错误是一样的。

法典:

<?php
use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
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');
}
}

尝试在Schema::create()之前添加以下条件

if (!Schema::hasTable('users')) {
Schema::create('users',...)
}

users表迁移文件中,在方法中添加此行up()

Schema::dropIfExists('users');

喜欢这个

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

检查迁移表是否记录了"用户"表,将其删除,然后使用此工匠命令执行单个迁移

php artisan migrate:refresh --path=/database/migrations/fileName.php

或者使用以下方法重置迁移,然后再次迁移

php artisan migrate:reset 

最新更新