Welcome Guest, Not a member yet? Register   Sign In
Why i cannot add foreign key in migration, it creates different one.
#1

(This post was last modified: 03-06-2024, 05:07 AM by sarath_unrelax.)

Hello,
Hope you all doing well!,. I'm trying to modify an existing table to add a column which i need to be foreignkey  to other table but it not creating.

My code :

PHP Code:
<?php

namespace App\Database\Migrations;

use 
CodeIgniter\Database\Migration;

class 
AddLeaveApplicationIdToLeaveAdjustMentTable extends Migration
{
    public function up()
    {
        $fields = [

            'leave_application_id' => [
    
                
'type' => 'INT',
                'constraint' => 7,
                'unsigned' => true
            
],
        ];
    
        $this
->forge->addForeignKey('leave_application_id''leave_applications''id''''''leave_application_id_fk');
        $this->forge->addColumn('leave_adjustment'$fields);

    }

    public function down()
    {
        $this->forge->dropForeignKey('leave_application_id_fk''leave_adjustment');
        $this->forge->dropColumn('leave_adjustment''leave_application_id');

    }
    


This not creating foreignkey to the leave_applications table. instead it created "leave_adjustment_emp_id_foreign".

How i can solve this issue ?

This creates column called "leave_application_id" but not creating foreign key, what wrong im doing here ?
Reply
#2

See https://codeigniter4.github.io/CodeIgnit...to-a-table
Reply
#3

(03-06-2024, 04:42 PM)kenjis Wrote: See https://codeigniter4.github.io/CodeIgnit...to-a-table

So I need to add this also ?

PHP Code:
$this->forge->processIndexes('leave_adjustment');

I'm correct ? 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB