Yii 2.0: yii2-migration-utility

Automatically writes the create tables for migrations or create tables in general. Uses MySQL

Yii2 Migration Utility

Updated August, 2015

Now supports table indexes, table options for each database type and table data.

This is a utility that writes the create table statement for migrations. The table(s), indexes, foreign keys must already exist.


  • MySQL
  • MsSQL
  • PgSQL
  • SQLite

It automatically writes out all:

  • tables
  • columns
  • column types
  • column defaults
  • primary keys
  • foreign key
  • indexes
  • Table data


The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-source "c006/yii2-migration-utility" "dev-master"

or add

"c006/yii2-migration-utility": "dev-master"

to the require section of your composer.json file.


Update either config/web.php (basic) or config/main.php (advanced)

        'modules'    => [
            'utility' => [
                'class' => 'c006\utility\migration\Module',

The tables must already exist in website schema.


Demo: http://demo.c006.us






  • Table options per database type
  • Table indexes
  • Table data

Comments / Suggestions

Please provide any helpful feedback or requests.


Total 5 comments

#19533 report it
jchambers at 2015/08/26 05:55am
jQuery is not defined

Hi J-C.

I do this.


    public $jsOptions = [
        'position' => View::POS_HEAD,
#19513 report it
J-C at 2015/08/13 04:10am
Uncaught ReferenceError: jQuery is not defined

Thank you for this extension!

Only the buttons "add all tables" and "change view" dont work for me, as I get the following error:

Uncaught ReferenceError: jQuery is not defined

In my opinion, it is due to the fact that in my template jQuery is called only at line 369:

<script src="/assets/ae07d411/jquery.js"></script>

but the extension needs it already in line 279.

Do you have a suggestion, how to solve it?

#19484 report it
jchambers at 2015/07/23 05:29pm
New version out v2.x

My apologies for the delay in responding. New version 2.x is out.

#17763 report it
jchambers at 2014/07/20 11:18pm

I see your point and will update the code.

Thanks for your input.

#17758 report it
ThePr0f3550r at 2014/07/20 07:15pm
You should see example

Good job, but You should see example in core of Yii

For example, for Your table, table user should :

$this->createTable('{{%user}}', [
            'id'            => Schema::TYPE_PK,
            'username'      => Schema::TYPE_STRING . '(25) NOT NULL',
            'email'         => Schema::TYPE_STRING . '(255) NOT NULL',
            'password_hash' => Schema::TYPE_STRING . '(60) NOT NULL',
            'auth_key'      => Schema::TYPE_STRING . '(32) NOT NULL',
            // confirmation
            'confirmation_token'   => Schema::TYPE_STRING . '(32)',
            'confirmation_sent_at' => Schema::TYPE_INTEGER,
            'confirmed_at'         => Schema::TYPE_INTEGER,
            'unconfirmed_email'    => Schema::TYPE_STRING . '(255)',
            // recovery
            'recovery_token'   => Schema::TYPE_STRING . '(32)',
            'recovery_sent_at' => Schema::TYPE_INTEGER,
            // block
            'blocked_at' => Schema::TYPE_INTEGER,
            // RBAC
            'role' => Schema::TYPE_STRING . '(255)',
            // trackable
            'registered_from' => Schema::TYPE_INTEGER,
            'logged_in_from'  => Schema::TYPE_INTEGER,
            'logged_in_at'    => Schema::TYPE_INTEGER,
            // timestamps
            'created_at' => Schema::TYPE_INTEGER . ' NOT NULL',
            'updated_at' => Schema::TYPE_INTEGER . ' NOT NULL',
        ], $tableOptions);

Not only think MySQL but globally :)

Leave a comment

Please to leave your comment.

Create extension
No downloadable files yet