add foreignkey to event table

This commit is contained in:
2020-07-19 12:39:22 +02:00
parent fe14127648
commit 1e7e1fc09e
2 changed files with 19 additions and 3 deletions

View File

@@ -18,11 +18,23 @@ class CreateEventsTable extends Migration
$table->unsignedBigInteger('user_id');
$table->unsignedBigInteger('category_id');
$table->string('name');
$table->string('description')->nullable();
$table->text('description')->nullable();
$table->timestamp('start_date');
$table->timestamp('end_date')->nullable();
$table->string('location')->nullable();
$table->timestamps();
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('restrict')
->onUpdate('restrict');
$table->foreign('category_id')
->references('id')
->on('event_categories')
->onDelete('restrict')
->onUpdate('restrict');
});
}
@@ -33,6 +45,10 @@ class CreateEventsTable extends Migration
*/
public function down()
{
Schema::table('events', function (Blueprint $table) {
$table->dropForeign(['user_id']);
$table->dropForeign(['category_id']);
});
Schema::dropIfExists('events');
}
}