我只是不了解我的生命,所以在创建新表后运行php artisan migrate
时会如何发生此错误。
我已经搜索了网络和SO,并尝试了每个建议(例如php artisan migrate:fresh
),但似乎没有任何效果。
由于这阻碍了我的工作,我该怎么办才能解决此问题?
SQLSTATE[42S01]: Base table or view already exists: 1050 Table
'posts' already exists (SQL: create table `posts` (`id` bigint
unsigned not null auto_increment primary key, `user_id` int
unsigned not null, `body` varchar(140) not null, `created_at`
timestamp null, `updated_at` timestamp null) default character set
utf8mb4 collate 'utf8mb4_unicode_ci')
迁移:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePostsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('user_id')->unsigned();
$table->string('body', 140);
$table->timestamps();
$table->foreign('user_id')->references('id')->on('user')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('posts');
}
}
答案 0 :(得分:0)
请先删除表格,然后再运行migration命令或尝试php artisan migrate:fresh命令。