mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-11 19:20:01 +08:00
adjusted guide docs for SchemaBuilder
This commit is contained in:
@@ -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:
|
The following code shows how you may implement the migration class to create a `news` table:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
<?php
|
||||||
|
|
||||||
use yii\db\Schema;
|
use yii\db\Schema;
|
||||||
use yii\db\Migration;
|
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()
|
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
|
> Info: The mapping between abstract types and physical types is specified by
|
||||||
the [[yii\db\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class.
|
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:
|
could be written like the following:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
<?php
|
||||||
|
|
||||||
use yii\db\Schema;
|
use yii\db\Schema;
|
||||||
use yii\db\Migration;
|
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()
|
public function up()
|
||||||
{
|
{
|
||||||
$this->createTable('news', [
|
$this->createTable('news', [
|
||||||
'id' => Schema::primaryKey(),
|
'id' => $this->primaryKey(),
|
||||||
'title' => Schema::string()->notNull(),
|
'title' => $this->string()->notNull(),
|
||||||
'content' => Schema::text(),
|
'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>
|
### Transactional Migrations <span id="transactional-migrations"></span>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user