CodeIgniter Forums
How set up Migration in HMVC? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: How set up Migration in HMVC? (/showthread.php?tid=76826)



How set up Migration in HMVC? - jailin - 06-24-2020

My autoload setup

PHP Code:
$psr4 = [
         
'App'         => APPPATH,                // To ensure filters, etc still found,
     
APP_NAMESPACE => APPPATH,                // For custom namespace
     
'Config'      => APPPATH 'Config',
     
'Mod'         => ROOTPATH 'mod',        
]; 

My migration file path

Code:
/mod/System/Database/Migrations/xxxxx_add_system.php


I use "php spark migrate" and show 

Code:
CodeIgniter CLI Tool - Version 4.0.3 - Server-Time: 2020-06-24 23:02:57pm

Running all new migrations...
Done

but no table created


RE: How set up Migration in HMVC? - marqone - 06-25-2020

Hi Jailin -- Usually when I run into stuff like that it is because I did not add the namespace to the file in question; is the namespace in the file defined at the top?


RE: How set up Migration in HMVC? - jailin - 06-26-2020

(06-25-2020, 12:17 PM)marqone Wrote: Hi Jailin -- Usually when I run into stuff like that it is because I did not add the namespace to the file in question; is the namespace in the file defined at the top?

My Migration file :

PHP Code:
<?php namespace Mod\System\Database\Migrations;

use 
CodeIgniter\Database\Migration;

class 
AddSystem extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type' => 'bigint',
                'auto_increment' => true,
                'unsigned' => true,
                'comment' => 'PK'
            ],
            'module_id' => [
                'type' => 'bigint',
                'unsigned' => true,
                'comment' => '模組ID'
            ],
            'setting_key' => [
                'type' => 'varchar',
                'constraint' => 255,
                'null' => false,
                'default' => '',
                'comment' => '設定欄位'
            ],
            'setting_value' => [
                'type' => 'text',
                'null' => true,
                'default' => null,
                'comment' => '設定值'
            ],
            'remark' => [
                'type' => 'text',
                'null' => true,
                'default' => null,
                'comment' => '設定值說明'
            ],
            'created_at' => [
                'type' => 'TIMESTAMP',
                'null' => false,
                'comment' => '新增時間'
            ],
            'updated_at' => [
                'type' => 'TIMESTAMP',
                'null' => false,
                'comment' => '最後更新時間'
            ]
        ]);

        $attributes = ['ENGINE' => 'InnoDB''COMMENT' => '系統設定'];
        $this->forge->addPrimaryKey('id');
        $this->forge->addUniqueKey('setting_key');
        $this->forge->addKey('module_id');
        $this->forge->createTable('system'true$attributes); 
    }

    //--------------------------------------------------------------------

    public function down()
    {
        //
    }