Welcome Guest, Not a member yet? Register   Sign In
Migration runs successfully but not creating tables
#1
Photo 

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]
Reply
#2

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); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(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';
Reply
#4

You can report it as an issue here:

CodeIgniter 4 Development

If you on the top toolbar you will see the issue button.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB