我之前创建了用户表。现在,我创建了一个新的迁移以在我的架构中创建一个新的 books 表。当我尝试运行命令时
php artisan migrate
表明:
[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, `username` varchar(255) not null, `email` varchar(255) n
ot null, `password` varchar(255) not null, `created_at` timestamp default 0
not null, `updated_at` timestamp default 0 not null) default character set
utf8 collate utf8_unicode_ci)
这是我的新迁移表:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateBooksTable extends Migration {
public function up()
{
Schema::create('books', function(Blueprint $table)
{
$table->increments('id');
$table->string('name');
$table->string('auther');
$table->string('area');
$table->timestamps();
});
}
public function down()
{
Schema::drop('books');
}
}
我怎样才能摆脱错误?
原文由 MD. Atiqur Rahman 发布,翻译遵循 CC BY-SA 4.0 许可协议
你需要跑
如果这也失败了,只需进入并删除您可能必须做的所有表,因为您的迁移表似乎被搞砸了,或者当您运行先前的回滚时您的用户表没有删除该表。
编辑:
发生这种情况的原因是您之前运行了回滚,并且代码中有一些错误或没有删除表。然而,这仍然会弄乱 laravel 迁移表,并且就它而言,您现在没有将用户表向上推的记录。但是,用户表确实已经存在,并且会抛出此错误。