Welcome Guest, Not a member yet? Register   Sign In
how to add index in addcolumn migration codeigniter 4
#1

PHP Code:
how can i add index on code_id and referral_code

<?php

namespace App\Database\Migrations;

use 
CodeIgniter\Database\Migration;

class 
AddColumUser extends Migration
{
    public function up()
    {
        $fields = [
            'fullname' => [
                'type' => 'VARCHAR',
                'constraint' => '100',
                'null' => false,
                'after' => 'balance',
            ],
            'phone' => [
                'type' => 'VARCHAR',
                'constraint' => '100',
                'null' => false,
                'after' => 'balance',
            ],
            'telegram' => [
                'type' => 'VARCHAR',
                'constraint' => '100',
                'null' => true,
                'after' => 'balance',
            ],
            'whatsapp' => [
                'type' => 'VARCHAR',
                'constraint' => '100',
                'null' => true,
                'after' => 'balance',
            ],
            'line' => [
                'type' => 'VARCHAR',
                'constraint' => '100',
                'null' => true,
                'after' => 'balance',
            ],
            'gender' => [
                'type' => 'ENUM',
                'constraint' => ['Male''Female'],
                'null' => true,
                'after' => 'balance',
            ],
            'address' => [
                'type' => 'VARCHAR',
                'constraint' => '255',
                'null' => true,
                'after' => 'balance',
            ],
            'postcode' => [
                'type' => 'VARCHAR',
                'constraint' => '50',
                'null' => true,
                'after' => 'balance',
            ],
            'state' => [
                'type' => 'VARCHAR',
                'constraint' => '150',
                'null' => true,
                'after' => 'balance',
            ],
            'referral_code' => [
                'type' => 'VARCHAR',
                'constraint' => '10',
                'null' => false,
                'after' => 'balance',
            ],
            'code_id' => [
                'type' => 'VARCHAR',
                'constraint' => '10',
                'null' => false,
                'after' => 'balance',
            ]
        ];
        $this->forge->addColumn('users'$fields);
        $this->forge->addKey(['referral_code''code_id']);
    }

    public function down()
    {
        $drop_colum = [
            'fullname',
            'phone'
            'telegram',
            'whatsapp',
            'line',
            'gender',
            'address',
            'postcode',
            'state',
            'referral_code',
            'code_id',
        ];
        $this->forge->dropColumn('users'$drop_colum);
    }

Reply


Messages In This Thread
how to add index in addcolumn migration codeigniter 4 - by devo - 05-04-2022, 06:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB