N
N
nlan2014-08-01 10:53:19
Yii
nlan, 2014-08-01 10:53:19

How to create an enum field in Yii2 in migration?

$this->createTable('credit_cards', [
            'id' => 'pk',
            'title' => Schema::TYPE_STRING . ' NOT NULL',
            'content' => Schema::TYPE_TEXT,
    ]);

For example, you need to create a `show` field with possible data 'yes', 'no' and set it to 'yes' by default

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Papa, 2014-08-01
@nlan

...
'show' => 'ENUM(`yes`, `no`) NOT NULL DEFAULT `yes`',
...

A
ArtLabStudio, 2015-11-13
@ArtLabStudio

I suffered so much until I found it, now on yii2 (Apache-2.4 | PHP-5.5 | MySQL-5.5) it is relevant like this:

'status' => "enum('" . active . "','" . inactive . "') NOT NULL DEFAULT '" . active . "'",

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question