Answer the question
In order to leave comments, you need to log in
How to link two tables one to one?
There are two tables: projects
Schema::create('projects', function (Blueprint $table) {
$table->increments('id');
$table->integer('tender_id')->unsigned();
$table->string('fullname')->nullable(true);
$table->foreign('tender_id')->references('id')->on('tenders');
$table->timestamps();
});
Schema::create('tenders', function (Blueprint $table) {
$table->increments('id');
$table->integer('project_id')->unsigned();
$table->string('fullname')->nullable(true);
$table->foreign('project_id')->references('id')->on('projects');
$table->timestamps();
});
Answer the question
In order to leave comments, you need to log in
The problem is that I'm trying to create a table with a foreign key that points to a table that hasn't been created yet.
Schema::create('tenders', function (Blueprint $table) {
$table->increments('id');
$table->integer('project_id')->unsigned();
$table->string('fullname')->nullable(true);
$table->timestamps();
});
Schema::create('projects', function (Blueprint $table) {
$table->increments('id');
$table->integer('tender_id')->unsigned();
$table->string('fullname')->nullable(true);
$table->foreign('tender_id')->references('id')->on('tenders');
$table->timestamps();
});
Schema::table('tenders', function (Blueprint $table) {
$table->foreign('project_id')->references('id')->on('projects');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question