【发布时间】:2020-07-17 08:46:29
【问题描述】:
文章表
public function up()
{
Schema::create('Articles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('user_id')->unsigned();
$table->string('title');
$table->string('body');
$table->timestamps();
$table->foreign('user_id')->references('id')
->on('users')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('Articles');
}
标签表
public function up()
{
Schema::create('tags', function (Blueprint $table)
{
$table->bigIncrements('id');
$table->string('name');
$table->timestamps();
});
Schema::create('article_tag',function (Blueprint $table)
{
$table->integer('article_id')->unsigned()->index();
$table->foreign('article_id')->references('id')->
on('articles')->onDelete('cascade');
$table->integer('tag_id')->unsigned()->index();
$table->foreign('tag_id')->references('id')->
on('tags')->onDelete('cascade');
$table->timestamps();
});
}
我想在 phpmyadmin 中创建标签表,但在 php artisan migrate 命令后遇到此错误
错误
`$ php artisan 迁移 迁移:2020_04_01_195718_create_articles_table
Illuminate\Database\QueryException : SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'articles' already exists (SQL: create table Articles (id bigint unsigned not null auto_increment prim
ary key, user_id int unsigned not null, title varchar(255) not null, body varchar(255) not null, created_at timestamp null, updated_at timestamp null) 默认字符集 utf8mb4 collate 'utf8mb4_un
icode_ci')`
【问题讨论】:
-
清除迁移表。然后运行“php artisan migrate”命令并显示错误(如果有)。