Skip to content

Instantly share code, notes, and snippets.

@datamweb
Last active April 10, 2022 00:59
Show Gist options
  • Save datamweb/f786017dcc92d135d6bd6c0a7040d195 to your computer and use it in GitHub Desktop.
Save datamweb/f786017dcc92d135d6bd6c0a7040d195 to your computer and use it in GitHub Desktop.
Add field type SET to table via Codeigniter Migration

Add field type SET to table via Codeigniter Migration

Sql Sample::

ALTER TABLE `table_name` ADD `my_column` SET('optionOne','optionTwo') NULL DEFAULT NULL COMMENT 'Comment for Columm';

Codeigniter Migration :: YourMigration.php

<?php
namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class YourMigration extends Migration
{
    public function up()
    {
        //
        $this->forge->addField([
            'id' => [
                    'type'           => 'INT',
                    'constraint'     => 11,
                    'unsigned'       => true,
                    'auto_increment' => true,
            ],

            //  Note lock here
            "my_column SET('optionOne','optionTwo') NULL DEFAULT NULL COMMENT 'Comment for Columm'",
        ]);
        $this->forge->addKey('id', true);
        $this->forge->createTable('table_name');
    }

    public function down()
    {
        //drop 'alert_messages' table
        $this->forge->dropTable('table_name');
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment