articles table
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');
}
tags table
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();
});
}
i want to make tags table in phpmyadmin fut faced to this error after php artisan migrate command
error
`$ php artisan migrate
Migrating: 2020_04_01_195718_create_articles_table
IlluminateDatabaseQueryException : 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) default character set utf8mb4 collate ‘utf8mb4_un
icode_ci’)`
3
Answers
try this code for user_id table
Use To Migrate All Tables
If you don’t want to loss your another tables data
Just goto mysql or phpmyadmin then delete the table and also from migrations
then re-run
try this