Yii2: Why is not supported in the Migration tinyint

Created on 8 Mar 2016  Â·  7Comments  Â·  Source: yiisoft/yii2

Why is not supported in the Migration tinyint

Most helpful comment

This data type exists in MySQL only, therefore we did not create a shortcut for it.

All 7 comments

        $this->createTable('{{%my_table}}', [
            'id' => $this->primaryKey(),
            'other' => 'tinyint not null',
        ]);

@mdmunir I think to do

$this->createTable('{{%my_table}}', [
            'id' => $this->primaryKey(),
            'other' => $this->tinyint()->notNull(),
        ]);

This data type exists in MySQL only, therefore we did not create a shortcut for it.

@SilverFire then what about creating a generic method, where we can tell the type and length?

$this->createTable('{{%my_table}}', [
            'id' => $this->primaryKey(),
            'other' => $this->nameForGenericColumnCreator('tinyint', 3)->notNull()->defaultValue(0)->after('field'),
        ]);

It's bad not to have a specific type because when we make a schema synchronization always accuses fails because the tinyint field.

Simply ignore their existence should not be the best option.

I believe that other DBMS must have the same problem of specific types and would be resolved with this general solution.

Cheers!!

@thiagotalma

'other' => (new yii\db\ColumnSchemaBuilder('random', 3, $this->db))->otherMethods(),

tinyint() is useful when i use mysql。 i write code
like 'tinyint not null' ,then if i want use it for other database,i shoud write like this everywhere
$this->db->driverName === 'mysql'?'tinyint not null' :$this->smallInt()->notNull()

$this->tinyInteger(1)->unsigned()

Was this page helpful?
0 / 5 - 0 ratings