P
P
Padre2018-02-03 21:53:53
Yii
Padre, 2018-02-03 21:53:53

Syntax of migrations in Yii2?

1. Where can I find the current migration syntax for the current version of the framework? Because after the command in the console, the up() function was created and in it:

$this->createTable('testmig', [
            'id' => $this->primaryKey(),
        ]);

But there is an option like this:
$this->createTable('news', [
            'id' => Schema::TYPE_PK,
            'title' => Schema::TYPE_STRING . ' NOT NULL',
            'content' => Schema::TYPE_TEXT,
        ]);

Is he outdated?
2. How to make varchar, or specify values, for example 5,2 when creating DECIMAL? On the net I saw only a variant with a line: but the lines, as it were, are also different ...
'title' => $this->string(),

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OKyJIucT, 2018-02-03
@yii16

1. Both options are working, the first one on your list is newer, appeared in version 2.0.6
2.

'price' => $this->decimal(10, 2) // DECIMAL
'name' => $this->string(32) // varchar
либо 'name' => $this->char(8)

Documentation with a list of available fields here www.yiiframework.com/doc-2.0/yii-db-migration.html
Description with examples here https://github.com/yiisoft/yii2/blob/master/docs/g...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question