|
|
|
@ -94,11 +94,12 @@ when you upgrade the database with this migration, while the `down()` method is
|
|
|
|
|
The following code shows how you may implement the migration class to create a `news` table: |
|
|
|
|
|
|
|
|
|
```php |
|
|
|
|
<?php |
|
|
|
|
|
|
|
|
|
use yii\db\Schema; |
|
|
|
|
use yii\db\Migration; |
|
|
|
|
|
|
|
|
|
class m150101_185401_create_news_table extends \yii\db\Migration |
|
|
|
|
class m150101_185401_create_news_table extends Migration |
|
|
|
|
{ |
|
|
|
|
public function up() |
|
|
|
|
{ |
|
|
|
@ -140,22 +141,23 @@ to `Schema::TYPE_STRING` to specify that the column cannot be null.
|
|
|
|
|
> Info: The mapping between abstract types and physical types is specified by |
|
|
|
|
the [[yii\db\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class. |
|
|
|
|
|
|
|
|
|
Since 2.0.5 schema builder which provides more convenient way defining column schema was introduced so migration above |
|
|
|
|
Since version 2.0.5 schema builder which provides more convenient way defining column schema was introduced so migration above |
|
|
|
|
could be written like the following: |
|
|
|
|
|
|
|
|
|
```php |
|
|
|
|
<?php |
|
|
|
|
|
|
|
|
|
use yii\db\Schema; |
|
|
|
|
use yii\db\Migration; |
|
|
|
|
|
|
|
|
|
class m150101_185401_create_news_table extends \yii\db\Migration |
|
|
|
|
class m150101_185401_create_news_table extends Migration |
|
|
|
|
{ |
|
|
|
|
public function up() |
|
|
|
|
{ |
|
|
|
|
$this->createTable('news', [ |
|
|
|
|
'id' => Schema::primaryKey(), |
|
|
|
|
'title' => Schema::string()->notNull(), |
|
|
|
|
'content' => Schema::text(), |
|
|
|
|
'id' => $this->primaryKey(), |
|
|
|
|
'title' => $this->string()->notNull(), |
|
|
|
|
'content' => $this->text(), |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -167,6 +169,8 @@ class m150101_185401_create_news_table extends \yii\db\Migration
|
|
|
|
|
} |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
A list of all available methods for defining the column types is available in the API documentation of [[yii\db\SchemaBuilderTrait]]. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Transactional Migrations <span id="transactional-migrations"></span> |
|
|
|
|
|
|
|
|
|