CodeIgniter Forums
Migration runs successfully but not creating tables - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Migration runs successfully but not creating tables (/showthread.php?tid=78106)



Migration runs successfully but not creating tables - tekrda - 12-01-2020

Hi everyone,
I'm having problem with migration, migration runs successfully on CLI but it doesn't create any table except migration table which contains migration related detail. Any help?
pls find the images below:

[Image: cz08Dt.jpg][Image: 1lPUty.jpg][Image: SERDUX.jpg]


RE: Migration runs successfully but not creating tables - InsiteFX - 12-01-2020

I'm not sure on this one but I believe you need to add all the fields with addKey.
All the migrations that I have seen do it this way, see below.

PHP Code:
/*
 * Users
 */
$this->forge->addField([
    'id'               => ['type' => 'int''constraint' => 11'unsigned' => true'auto_increment' => true],
    'email'            => ['type' => 'varchar''constraint' => 255],
    'username'         => ['type' => 'varchar''constraint' => 30'null' => true],
    'password_hash'    => ['type' => 'varchar''constraint' => 255],
]);

$this->forge->addKey('id'true);
$this->forge->addUniqueKey('email');
$this->forge->addUniqueKey('username');

$this->forge->createTable('users'true); 



RE: Migration runs successfully but not creating tables - tekrda - 12-02-2020

(12-01-2020, 01:24 PM)InsiteFX Wrote: I'm not sure on this one but I believe you need to add all the fields with addKey.
All the migrations that I have seen do it this way, see below.

PHP Code:
/*
 * Users
 */
$this->forge->addField([
    'id'               => ['type' => 'int''constraint' => 11'unsigned' => true'auto_increment' => true],
    'email'            => ['type' => 'varchar''constraint' => 255],
    'username'         => ['type' => 'varchar''constraint' => 30'null' => true],
    'password_hash'    => ['type' => 'varchar''constraint' => 255],
]);

$this->forge->addKey('id'true);
$this->forge->addUniqueKey('email');
$this->forge->addUniqueKey('username');

$this->forge->createTable('users'true); 

Thanks for the reply,

i got the solution. the problem is that when you run migration, codeigniter does not generate any exception if there is any issue in your migration class, it silently says "Done" and does not create table in DB based on your schema. This behavior makes the developer clueless. This need to be addressed by codeigniter developers team.

the problem was that i had declared "email" field unique twice one in field's array and other is via addUniqueKey() function and also i had not specified DBGroup variable as  protected $DBGroup = 'default';


RE: Migration runs successfully but not creating tables - InsiteFX - 12-02-2020

You can report it as an issue here:

CodeIgniter 4 Development

If you on the top toolbar you will see the issue button.