-
devo
Member
-
Posts: 60
Threads: 27
Joined: Apr 2021
Reputation:
0
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); } }
-
kenjis
Administrator
-
Posts: 3,679
Threads: 97
Joined: Oct 2014
Reputation:
228
-
devo
Member
-
Posts: 60
Threads: 27
Joined: Apr 2021
Reputation:
0
05-07-2022, 02:46 AM
(This post was last modified: 05-07-2022, 02:48 AM by devo.)
(05-06-2022, 12:34 AM)InsiteFX Wrote: Database Forge Class
what did you try :
i try to add column and index to column code_id and referral_code
what did you get :
what i get is when i add column and index to my users table the column is added but index not added
what did you expect :
what i want is when i addcolum and index to table it must add the column and index the column
but i solve this problem alredy use query
(05-06-2022, 12:54 AM)kenjis Wrote: Missing: Means of adding indexes · Issue #4814 · codeigniter4/CodeIgniter4
https://github.com/codeigniter4/CodeIgni...ssues/4814
Use query() method.
https://codeigniter.com/user_guide/datab...ar-queries
yes i solve this problem use query
PHP 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->db->query("CREATE INDEX code_id ON users(code_id)"); $this->db->query("CREATE INDEX referral_code ON users(referral_code)"); }
public function down() { $drop_colum = [ 'fullname', 'phone', 'telegram', 'whatsapp', 'line', 'gender', 'address', 'postcode', 'state', 'referral_code', 'code_id', ]; $this->forge->dropColumn('users', $drop_colum); } }
|