laravel-5 - 当我有密钥对类型的数据时如何规范化表
问题描述
我正在制作一个平台,培训师可以在其中将课程添加到他的个人资料中。但在他添加课程之前,需要完成申请接受。
所以,我之前将我的数据库分为三个部分:
users | trainer | course
经过一些研究,我发现我必须进行数据库规范化,但我在设置它时遇到了问题。
现在我有trainer
桌子trainer_experience
和trainer_achievements
桌子。在培训师经验表中,我必须保存他们所穿职位和公司名称的数据。
我的教练表是这样的:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTrainersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('trainers', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('user_id');
$table->date('date_of_birth');
$table->integer('mobile_number');
$table->longText('address');
$table->string('id_proof');
$table->string('id_registration_number');
$table->string('high_school_name');
$table->string('graduation_college_name');
$table->string('graduation_course_name');
$table->string('post_graduation_college_name');
$table->string('post_graduation_course_name');
$table->string('phd_field_of_study');
$table->string('total_duration_of_training');
$table->integer('no_of_people_trained');
$table->boolean('paid_training');
$table->string('training_category');
$table->string('course_material_ready');
$table->string('youtube_link')->nullable();
$table->string('twitter_link')->nullable();
$table->string('instagram_link')->nullable();
$table->string('facebook_link')->nullable();
$table->string('linkedin_link')->nullable();
$table->string('blog_link')->nullable();
$table->string('website_link')->nullable();
$table->string('meetup_group_link')->nullable();
$table->timestamps();
$table->index('user_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('trainers');
}
}
我如何存储数据,以便我至少可以按照他们输入的顺序检索它?我需要制作两张不同的桌子吗?我有什么最好的选择?
解决方案
trainer_experience
您必须在数据中找出trainer_achievements
是否可重用?trainer_experience
并且trainer_achievements
相互依赖?- 使用多态关系以获得最佳用途。
推荐阅读
- php - Laravel \ Socialite \ Two \ InvalidStateException Facebook Socialite 中没有消息错误
- sandbox - 错误:未在此范围内声明“scmp_filter_ctx”
- error-handling - 无法在 IronPython 中捕获 .NET 错误
- python - numpy.dot 对大型数组有精度限制吗?
- php - 安装和使用 gnug
- jenkins - 无法使用 jenkins 设置的 perforce 票证来自动执行 perforce 登录
- javascript - 无法读取属性 'transition' null chartjs
- html - 有没有办法消除我的 CSS3 网格中的间隙,并使网格居中?
- postgresql - 在 Postgres 中处理多个并发读取查询
- mysql - MySQL Schema 建议:不可预测的字段添加