PHP artisan migrate命令出现错误?
当我运行命令php artisan migrate时,它会导致以下错误 [Illumb\Database\QueryException]SQLSTATE[42S01]:基表或 视图已存在:1050表“用户”已存在SQL:create 表用户id int无符号非空自动增量主键, 名称varchar255不为空,电子邮件varchar255不为空, 密码varchar255不为null,请记住\u令牌varchar100 null, 在时间戳为空时创建\u,在时间戳为空时更新\u默认值 字符集utf8mb4校对utf8mb4\u unicode\u ciPHP artisan migrate命令出现错误?,php,mysql,laravel,Php,Mysql,Laravel,当我运行命令php artisan migrate时,它会导致以下错误 [Illumb\Database\QueryException]SQLSTATE[42S01]:基表或 视图已存在:1050表“用户”已存在SQL:create 表用户id int无符号非空自动增量主键, 名称varchar255不为空,电子邮件varchar255不为空, 密码varchar255不为null,请记住\u令牌varchar100 null, 在时间戳为空时创建\u,在时间戳为空时更新\u默认值 字符集utf
我正在Windows上使用Laravel 5.4。如果您在该问题中粘贴了准确的代码,那么我可以看到一个简单的拼写错误
email varchar(255) not n ull,
我知道这是我愚蠢的回答。
但您可以使用:
php artisan migrate --force
php artisan migrate:refresh
php artisan migrate:reset
最好用这个。也许它会起作用:
php artisan migrate:rollback
请按照以下步骤进行操作
检查你的数据库
如果存在“用户”表出口,则DROPuserstable
现在
第一步。要创建迁移,请使用make:migration
命令:-php artisan make:migration create\u yourtablename\u table
第二步。键入以下命令:php artisan migrate它让您知道“Users”表已经存在—当您运行迁移时—它正在尝试创建该表,但它已经存在 这通常是因为您以前尝试过运行命令“php artisan migrate”。必须回滚以“撤消”这些更改,或者清除数据库表 您可以运行:
php artisan migrate:rollback
这样就可以去掉所有的表,然后你就可以运行了
php artisan migrate
它应该适当地加载所有内容
替代方法?登录数据库并从数据库中物理删除这些表。然后,您可以再次运行迁移,它将正常工作
有一点问题:首先检查您的迁移:它应该具有以下功能:
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
如果没有,回滚将不会删除users表,您仍然会遇到这个问题,这意味着您必须登录到DB并手动删除表
如果使用此命令创建迁移,将自动包括回滚功能:
php artisan make:migration create_yourtablename_table
使用
我也有同样的问题,我所做的是在用户和密码重置迁移的up函数中注释掉行,然后我尝试了它。我不知道这是否是正确的方法!如果我错了,请纠正我。请回答我的问题 你的问题可以解决 通过更改create_users_table.php
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//Add this line
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();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
可能重复:
php artisan migrate:rollback
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//Add this line
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();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}