我希望能对我的人际关系有所了解。我有一个像这样的简单迁移
Schema::create('project_docs', function(Blueprint $table)
{
$table->increments('id');
$table->integer('projectId')->unsigned()->default(0);
$table->foreign('projectId')->references('id')->on('projects')->onDelete('cascade');
$table->longText('whatData');
$table->longText('whoData');
$table->timestamps();
});
Schema::create('projects', function (Blueprint $table) {
$table->increments('id');
$table->string('projectId')->default('');
$table->string('clientStatus')->default('');
$table->string('contactName')->default('');
$table->string('projectName')->default('');
$table->timestamps();
});
我希望这会形成一对一的关系,但是当我在MySQL Workbench中打开数据库并显示EER图时,它表明项目可以有一个到多个project_docs。
我知道他们在Laravel的模型中我可以定义他们的一对一关系,我是否需要改变上面产生的一对多关系,或者我只是忽略它?
由于
答案 0 :(得分:0)
我相信这一改变将使MySQL Workbench在图中将其显示为一对一的关系。
Schema::create('project_docs', function(Blueprint $table)
{
$table->increments('id');
// Note UNIQUE here.
// Personally I wouldn't define a default. Maybe add it as nullable?.
$table->integer('projectId')->unsigned()->unique();
$table->foreign('projectId')->references('id')
->on('projects')
->onDelete('cascade');
$table->longText('whatData');
$table->longText('whoData');
$table->timestamps();
});
快一点,您真的需要projectID
表中的projects
字段吗?