In my project i have Journals table, Monthlies table, Loan table, Investment table. Journal table has payment_id which i want to give foreign key for the monthlies, loan and investment tables ID. I have tried this but in migration it occurs error "duplicate key on write or update"
what i want to do is , I am trying to insert loan, investment, monthlies id on journals table payment_id when loan, investment, monthlies are created. I can insert only one tables id on journals table payment_id (through foreign key relationship in migration) not multiple...how can i do that?
public function up()
{
Schema::create('journals', function (Blueprint $table) {
$table->increments('id');
$table->double('amount');
$table->integer('payment_id')->unsigned();
$table->enum('payment_format', ['monthly', 'investment', 'loan', 'income', 'expense', 'others']);
$table->string('short_description');
$table->integer('created_by')->unsigned();
$table->integer('updated_by')->unsigned();
$table->dateTime('deleted_at');
$table->timestamps();
$table->foreign('payment_id')->references('id')->on('monthlies')
->onUpdate('cascade')->onDelete('cascade');
$table->foreign('payment_id')->references('id')->on('investments')
->onUpdate('cascade')->onDelete('cascade');
$table->foreign('payment_id')->references('id')->on('loans')
->onUpdate('cascade')->onDelete('cascade');
$table->foreign('created_by')->references('id')->on('users')
->onUpdate('cascade')->onDelete('cascade');
$table->foreign('updated_by')->references('id')->on('users')
->onUpdate('cascade')->onDelete('cascade');
});
}