mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
Fixes #11808: _table
and _column
suffixes are now required when generating migration
This commit is contained in:

committed by
Alexander Makarov

parent
b0bb8649a3
commit
5992eea571
@ -185,14 +185,14 @@ Existe una lista de todos los métodos disponibles para la definición de tipos
|
||||
|
||||
Desde la versión 2.0.7 la consola provee una manera muy conveniente de generar migraciones.
|
||||
|
||||
Si el nombre de la migración tiene una forma especial, por ejemplo `create_xxx` o `drop_xxx` entonces el archivo de la migración generada
|
||||
Si el nombre de la migración tiene una forma especial, por ejemplo `create_xxx_table` o `drop_xxx_table` entonces el archivo de la migración generada
|
||||
contendrá código extra, en este caso para crear/eliminar tablas.
|
||||
A continuación se describen todas estas variantes.
|
||||
|
||||
### Crear Tabla
|
||||
|
||||
```php
|
||||
yii migrate/create create_post
|
||||
yii migrate/create create_post_table
|
||||
```
|
||||
|
||||
esto genera
|
||||
@ -201,7 +201,7 @@ esto genera
|
||||
/**
|
||||
* Handles the creation for table `post`.
|
||||
*/
|
||||
class m150811_220037_create_post extends Migration
|
||||
class m150811_220037_create_post_table extends Migration
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -226,7 +226,7 @@ class m150811_220037_create_post extends Migration
|
||||
Para crear las columnas en ese momento, las puedes especificar vía la opción `--fields`.
|
||||
|
||||
```php
|
||||
yii migrate/create create_post --fields="title:string,body:text"
|
||||
yii migrate/create create_post_table --fields="title:string,body:text"
|
||||
```
|
||||
|
||||
genera
|
||||
@ -235,7 +235,7 @@ genera
|
||||
/**
|
||||
* Handles the creation for table `post`.
|
||||
*/
|
||||
class m150811_220037_create_post extends Migration
|
||||
class m150811_220037_create_post_table extends Migration
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -263,7 +263,7 @@ class m150811_220037_create_post extends Migration
|
||||
Puedes especificar más parámetros para las columnas.
|
||||
|
||||
```php
|
||||
yii migrate/create create_post --fields="title:string(12):notNull:unique,body:text"
|
||||
yii migrate/create create_post_table --fields="title:string(12):notNull:unique,body:text"
|
||||
```
|
||||
|
||||
genera
|
||||
@ -272,7 +272,7 @@ genera
|
||||
/**
|
||||
* Handles the creation for table `post`.
|
||||
*/
|
||||
class m150811_220037_create_post extends Migration
|
||||
class m150811_220037_create_post_table extends Migration
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -304,7 +304,7 @@ class m150811_220037_create_post extends Migration
|
||||
Desde 2.0.8 el generador soporta claves foráneas utilizando la palabra clave `foreignKey`.
|
||||
|
||||
```php
|
||||
yii migrate/create create_post --fields="author_id:integer:notNull:foreignKey(user),category_id:integer:defaultValue(1):foreignKey,title:string,body:text"
|
||||
yii migrate/create create_post_table --fields="author_id:integer:notNull:foreignKey(user),category_id:integer:defaultValue(1):foreignKey,title:string,body:text"
|
||||
```
|
||||
|
||||
genera
|
||||
@ -317,7 +317,7 @@ genera
|
||||
* - `user`
|
||||
* - `category`
|
||||
*/
|
||||
class m160328_040430_create_post extends Migration
|
||||
class m160328_040430_create_post_table extends Migration
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -422,13 +422,13 @@ una columna llamada `author_id` con una clave foránea a la tabla `user` mientra
|
||||
### Eliminar Tabla
|
||||
|
||||
```php
|
||||
yii migrate/create drop_post --fields="title:string(12):notNull:unique,body:text"
|
||||
yii migrate/create drop_post_table --fields="title:string(12):notNull:unique,body:text"
|
||||
```
|
||||
|
||||
genera
|
||||
|
||||
```php
|
||||
class m150811_220037_drop_post extends Migration
|
||||
class m150811_220037_drop_post_table extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
@ -448,19 +448,19 @@ class m150811_220037_drop_post extends Migration
|
||||
|
||||
### Agregar Columna
|
||||
|
||||
Si el nombre de la migración está en la forma `add_xxx_to_yyy` entonces el archivo generado contendrá
|
||||
Si el nombre de la migración está en la forma `add_xxx_column_to_yyy_table` entonces el archivo generado contendrá
|
||||
las declaraciones `addColumn` y `dropColumn` necesarias.
|
||||
|
||||
Para agregar una columna:
|
||||
|
||||
```php
|
||||
yii migrate/create add_position_to_post --fields="position:integer"
|
||||
yii migrate/create add_position_column_to_post_table --fields="position:integer"
|
||||
```
|
||||
|
||||
genera
|
||||
|
||||
```php
|
||||
class m150811_220037_add_position_to_post extends Migration
|
||||
class m150811_220037_add_position_column_to_post_table extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
@ -476,17 +476,17 @@ class m150811_220037_add_position_to_post extends Migration
|
||||
|
||||
### Eliminar Columna
|
||||
|
||||
Si el nombre de la migración está en la forma `drop_xxx_from_yyy` entonces el archivo generado contendrá
|
||||
Si el nombre de la migración está en la forma `drop_xxx_column_from_yyy_table` entonces el archivo generado contendrá
|
||||
las declaraciones `addColumn` y `dropColumn` necesarias.
|
||||
|
||||
```php
|
||||
yii migrate/create drop_position_from_post --fields="position:integer"
|
||||
yii migrate/create drop_position_column_from_post_table --fields="position:integer"
|
||||
```
|
||||
|
||||
genera
|
||||
|
||||
```php
|
||||
class m150811_220037_drop_position_from_post extends Migration
|
||||
class m150811_220037_drop_position_column_from_post_table extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
@ -502,11 +502,11 @@ class m150811_220037_drop_position_from_post extends Migration
|
||||
|
||||
### Agregar Tabla de Unión
|
||||
|
||||
Si el nombre de la migración está en la forma `create_junction_xxx_and_yyy` entonces se generará el código necesario
|
||||
Si el nombre de la migración está en la forma `create_junction_table_for_xxx_and_yyy_tables` entonces se generará el código necesario
|
||||
para una tabla de unión.
|
||||
|
||||
```php
|
||||
yii migrate/create create_junction_post_and_tag --fields="created_at:dateTime"
|
||||
yii migrate/create create_junction_table_for_post_and_tag_tables --fields="created_at:dateTime"
|
||||
```
|
||||
|
||||
genera
|
||||
@ -519,7 +519,7 @@ genera
|
||||
* - `post`
|
||||
* - `tag`
|
||||
*/
|
||||
class m160328_041642_create_junction_post_and_tag extends Migration
|
||||
class m160328_041642_create_junction_table_for_post_and_tag_tables extends Migration
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
|
@ -177,14 +177,14 @@ class m150101_185401_create_news_table extends Migration
|
||||
バージョン 2.0.7 以降では、マイグレーション・コンソールがマイグレーションを生成する便利な方法を提供しています。
|
||||
|
||||
マイグレーションの名前が特定の形式である場合は、生成されるマイグレーション・ファイルに追加のコードが書き込まれます。
|
||||
例えば、`create_xxx` や `drop_xxx` であれば、テーブルの作成や削除をするコードが追加されます。
|
||||
例えば、`create_xxx_table` や `drop_xxx_table` であれば、テーブルの作成や削除をするコードが追加されます。
|
||||
以下で、この機能の全ての変種を説明します。
|
||||
|
||||
|
||||
### テーブルの作成
|
||||
|
||||
```php
|
||||
yii migrate/create create_post
|
||||
yii migrate/create create_post_table
|
||||
```
|
||||
|
||||
上記のコマンドは、次のコードを生成します。
|
||||
@ -193,7 +193,7 @@ yii migrate/create create_post
|
||||
/**
|
||||
* Handles the creation for table `post`.
|
||||
*/
|
||||
class m150811_220037_create_post extends Migration
|
||||
class m150811_220037_create_post_table extends Migration
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -218,7 +218,7 @@ class m150811_220037_create_post extends Migration
|
||||
テーブルのフィールドも直接に生成したい場合は、`--fields` オプションでフィールドを指定します。
|
||||
|
||||
```php
|
||||
yii migrate/create create_post --fields="title:string,body:text"
|
||||
yii migrate/create create_post_table --fields="title:string,body:text"
|
||||
```
|
||||
|
||||
これは、次のコードを生成します。
|
||||
@ -227,7 +227,7 @@ yii migrate/create create_post --fields="title:string,body:text"
|
||||
/**
|
||||
* Handles the creation for table `post`.
|
||||
*/
|
||||
class m150811_220037_create_post extends Migration
|
||||
class m150811_220037_create_post_table extends Migration
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -255,7 +255,7 @@ class m150811_220037_create_post extends Migration
|
||||
さらに多くのフィールド・パラメータを指定することも出来ます。
|
||||
|
||||
```php
|
||||
yii migrate/create create_post --fields="title:string(12):notNull:unique,body:text"
|
||||
yii migrate/create create_post_table --fields="title:string(12):notNull:unique,body:text"
|
||||
```
|
||||
|
||||
これは、次のコードを生成します。
|
||||
@ -264,7 +264,7 @@ yii migrate/create create_post --fields="title:string(12):notNull:unique,body:te
|
||||
/**
|
||||
* Handles the creation for table `post`.
|
||||
*/
|
||||
class m150811_220037_create_post extends Migration
|
||||
class m150811_220037_create_post_table extends Migration
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -297,7 +297,7 @@ class m150811_220037_create_post extends Migration
|
||||
バージョン 2.0.8 からは、`foreignKey` キーワードを使って外部キーを生成することができます。
|
||||
|
||||
```php
|
||||
yii migrate/create create_post --fields="author_id:integer:notNull:foreignKey(user),category_id:integer:defaultValue(1):foreignKey,title:string,body:text"
|
||||
yii migrate/create create_post_table --fields="author_id:integer:notNull:foreignKey(user),category_id:integer:defaultValue(1):foreignKey,title:string,body:text"
|
||||
```
|
||||
|
||||
これは、次のコードを生成します。
|
||||
@ -310,7 +310,7 @@ yii migrate/create create_post --fields="author_id:integer:notNull:foreignKey(us
|
||||
* - `user`
|
||||
* - `category`
|
||||
*/
|
||||
class m160328_040430_create_post extends Migration
|
||||
class m160328_040430_create_post_table extends Migration
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -413,13 +413,13 @@ class m160328_040430_create_post extends Migration
|
||||
### テーブルを削除する
|
||||
|
||||
```php
|
||||
yii migrate/create drop_post --fields="title:string(12):notNull:unique,body:text"
|
||||
yii migrate/create drop_post_table --fields="title:string(12):notNull:unique,body:text"
|
||||
```
|
||||
|
||||
これは、次のコードを生成します。
|
||||
|
||||
```php
|
||||
class m150811_220037_drop_post extends Migration
|
||||
class m150811_220037_drop_post_table extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
@ -439,18 +439,18 @@ class m150811_220037_drop_post extends Migration
|
||||
|
||||
### カラムを追加する
|
||||
|
||||
マイグレーションの名前が `add_xxx_to_yyy` の形式である場合、ファイルの内容は、必要となる `addColumn` と `dropColumn` を含むことになります。
|
||||
マイグレーションの名前が `add_xxx_column_to_yyy_table` の形式である場合、ファイルの内容は、必要となる `addColumn` と `dropColumn` を含むことになります。
|
||||
|
||||
カラムを追加するためには、次のようにします。
|
||||
|
||||
```php
|
||||
yii migrate/create add_position_to_post --fields="position:integer"
|
||||
yii migrate/create add_position_column_to_post_table --fields="position:integer"
|
||||
```
|
||||
|
||||
これが次のコードを生成します。
|
||||
|
||||
```php
|
||||
class m150811_220037_add_position_to_post extends Migration
|
||||
class m150811_220037_add_position_column_to_post_table extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
@ -466,16 +466,16 @@ class m150811_220037_add_position_to_post extends Migration
|
||||
|
||||
### カラムを削除する
|
||||
|
||||
マイグレーションの名前が `drop_xxx_from_yyy` の形式である場合、ファイルの内容は、必要となる `addColumn` と `dropColumn` を含むことになります。
|
||||
マイグレーションの名前が `drop_xxx_column_from_yyy_table` の形式である場合、ファイルの内容は、必要となる `addColumn` と `dropColumn` を含むことになります。
|
||||
|
||||
```php
|
||||
yii migrate/create drop_position_from_post --fields="position:integer"
|
||||
yii migrate/create drop_position_column_from_post_table --fields="position:integer"
|
||||
```
|
||||
|
||||
これは、次のコードを生成します。
|
||||
|
||||
```php
|
||||
class m150811_220037_drop_position_from_post extends Migration
|
||||
class m150811_220037_drop_position_column_from_post_table extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
@ -491,10 +491,10 @@ class m150811_220037_drop_position_from_post extends Migration
|
||||
|
||||
### 中間テーブルを追加する
|
||||
|
||||
マイグレーションの名前が `create_junction_xxx_and_yyy` の形式である場合は、中間テーブルを作成するのに必要となるコードが生成されます。
|
||||
マイグレーションの名前が `create_junction_table_for_xxx_and_yyy_tables` の形式である場合は、中間テーブルを作成するのに必要となるコードが生成されます。
|
||||
|
||||
```php
|
||||
yii migrate/create create_junction_post_and_tag --fields="created_at:dateTime"
|
||||
yii migrate/create create_junction_table_for_post_and_tag_tables --fields="created_at:dateTime"
|
||||
```
|
||||
|
||||
これは、次のコードを生成します。
|
||||
@ -507,7 +507,7 @@ yii migrate/create create_junction_post_and_tag --fields="created_at:dateTime"
|
||||
* - `post`
|
||||
* - `tag`
|
||||
*/
|
||||
class m160328_041642_create_junction_post_and_tag extends Migration
|
||||
class m160328_041642_create_junction_table_for_post_and_tag_tables extends Migration
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
|
@ -160,19 +160,19 @@ class m150101_185401_create_news_table extends Migration
|
||||
|
||||
Начиная с версии 2.0.7 появился удобный способ создания миграций из консоли.
|
||||
|
||||
В том случае, если миграция названа особым образом, таким как, например, `create_xxx` или `drop_xxx` сгенерированный
|
||||
В том случае, если миграция названа особым образом, таким как, например, `create_xxx_table` или `drop_xxx_table` сгенерированный
|
||||
файл миграции будет содержать дополнительный код.
|
||||
|
||||
### Создание таблицы
|
||||
|
||||
```php
|
||||
yii migrate/create create_post
|
||||
yii migrate/create create_post_table
|
||||
```
|
||||
|
||||
сгенерирует
|
||||
|
||||
```php
|
||||
class m150811_220037_create_post extends Migration
|
||||
class m150811_220037_create_post_table extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
@ -191,13 +191,13 @@ class m150811_220037_create_post extends Migration
|
||||
Чтобы сразу создать поля таблицы, укажите их через опцию `--fields`.
|
||||
|
||||
```php
|
||||
yii migrate/create create_post --fields=title:string,body:text
|
||||
yii migrate/create create_post_table --fields=title:string,body:text
|
||||
```
|
||||
|
||||
сгенерирует
|
||||
|
||||
```php
|
||||
class m150811_220037_create_post extends Migration
|
||||
class m150811_220037_create_post_table extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
@ -218,13 +218,13 @@ class m150811_220037_create_post extends Migration
|
||||
Можно указать дополнительные параметры.
|
||||
|
||||
```php
|
||||
yii migrate/create create_post --fields=title:string(12):notNull:unique,body:text
|
||||
yii migrate/create create_post_table --fields=title:string(12):notNull:unique,body:text
|
||||
```
|
||||
|
||||
сгенерирует
|
||||
|
||||
```php
|
||||
class m150811_220037_create_post extends Migration
|
||||
class m150811_220037_create_post_table extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
@ -249,13 +249,13 @@ class m150811_220037_create_post extends Migration
|
||||
### Удаление таблицы
|
||||
|
||||
```php
|
||||
yii migrate/create drop_post --fields=title:string(12):notNull:unique,body:text
|
||||
yii migrate/create drop_post_table --fields=title:string(12):notNull:unique,body:text
|
||||
```
|
||||
|
||||
сгенерирует
|
||||
|
||||
```php
|
||||
class m150811_220037_drop_post extends Migration
|
||||
class m150811_220037_drop_post_table extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
@ -275,18 +275,18 @@ class m150811_220037_drop_post extends Migration
|
||||
|
||||
### Добавление столбца
|
||||
|
||||
Если имя миграции задано как `add_xxx_to_yyy`, файл будет содержать необходимые методы `addColumn` и `dropColumn`.
|
||||
Если имя миграции задано как `add_xxx_column_to_yyy_table`, файл будет содержать необходимые методы `addColumn` и `dropColumn`.
|
||||
|
||||
Для добавления столбца:
|
||||
|
||||
```php
|
||||
yii migrate/create add_position_to_post --fields=position:integer
|
||||
yii migrate/create add_position_column_to_post_table --fields=position:integer
|
||||
```
|
||||
|
||||
сгенерирует
|
||||
|
||||
```php
|
||||
class m150811_220037_add_position_to_post extends Migration
|
||||
class m150811_220037_add_position_column_to_post_table extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
@ -302,16 +302,16 @@ class m150811_220037_add_position_to_post extends Migration
|
||||
|
||||
### Удаление столбца
|
||||
|
||||
Если имя миграции задано как `drop_xxx_from_yyy`, файл будет содержать необходимые методы `addColumn` и `dropColumn`.
|
||||
Если имя миграции задано как `drop_xxx_column_from_yyy_table`, файл будет содержать необходимые методы `addColumn` и `dropColumn`.
|
||||
|
||||
```php
|
||||
yii migrate/create drop_position_from_post --fields=position:integer
|
||||
yii migrate/create drop_position_column_from_post_table --fields=position:integer
|
||||
```
|
||||
|
||||
сгенерирует
|
||||
|
||||
```php
|
||||
class m150811_220037_drop_position_from_post extends Migration
|
||||
class m150811_220037_drop_position_column_from_post_table extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
@ -327,10 +327,10 @@ class m150811_220037_drop_position_from_post extends Migration
|
||||
|
||||
### Добавление промежуточной таблицы
|
||||
|
||||
Если имя миграции задано как `create_junction_xxx_and_yyy`, файл будет содержать код для создания промежуточной таблцы.
|
||||
Если имя миграции задано как `create_junction_table_for_xxx_and_yyy_tables`, файл будет содержать код для создания промежуточной таблцы.
|
||||
|
||||
```php
|
||||
yii migrate/create create_junction_post_and_tag
|
||||
yii migrate/create create_junction_table_for_post_and_tag_tables
|
||||
```
|
||||
|
||||
сгенерирует
|
||||
|
@ -185,14 +185,14 @@ A list of all available methods for defining the column types is available in th
|
||||
|
||||
Since version 2.0.7 migration console provides a convenient way to create migrations.
|
||||
|
||||
If the migration name is of a special form, for example `create_xxx` or `drop_xxx` then the generated migration
|
||||
If the migration name is of a special form, for example `create_xxx_table` then the generated migration
|
||||
file will contain extra code, in this case for creating/dropping tables.
|
||||
In the following all variants of this feature are described.
|
||||
|
||||
### Create Table
|
||||
|
||||
```php
|
||||
yii migrate/create create_post
|
||||
yii migrate/create create_post_table
|
||||
```
|
||||
|
||||
generates
|
||||
@ -201,7 +201,7 @@ generates
|
||||
/**
|
||||
* Handles the creation for table `post`.
|
||||
*/
|
||||
class m150811_220037_create_post extends Migration
|
||||
class m150811_220037_create_post_table extends Migration
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -226,7 +226,7 @@ class m150811_220037_create_post extends Migration
|
||||
To create table fields right away, specify them via `--fields` option.
|
||||
|
||||
```php
|
||||
yii migrate/create create_post --fields="title:string,body:text"
|
||||
yii migrate/create create_post_table --fields="title:string,body:text"
|
||||
```
|
||||
|
||||
generates
|
||||
@ -235,7 +235,7 @@ generates
|
||||
/**
|
||||
* Handles the creation for table `post`.
|
||||
*/
|
||||
class m150811_220037_create_post extends Migration
|
||||
class m150811_220037_create_post_table extends Migration
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -263,7 +263,7 @@ class m150811_220037_create_post extends Migration
|
||||
You can specify more field parameters.
|
||||
|
||||
```php
|
||||
yii migrate/create create_post --fields="title:string(12):notNull:unique,body:text"
|
||||
yii migrate/create create_post_table --fields="title:string(12):notNull:unique,body:text"
|
||||
```
|
||||
|
||||
generates
|
||||
@ -272,7 +272,7 @@ generates
|
||||
/**
|
||||
* Handles the creation for table `post`.
|
||||
*/
|
||||
class m150811_220037_create_post extends Migration
|
||||
class m150811_220037_create_post_table extends Migration
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -304,7 +304,7 @@ class m150811_220037_create_post extends Migration
|
||||
Since 2.0.8 the generator supports foreign keys using the `foreignKey` keyword.
|
||||
|
||||
```php
|
||||
yii migrate/create create_post --fields="author_id:integer:notNull:foreignKey(user),category_id:integer:defaultValue(1):foreignKey,title:string,body:text"
|
||||
yii migrate/create create_post_table --fields="author_id:integer:notNull:foreignKey(user),category_id:integer:defaultValue(1):foreignKey,title:string,body:text"
|
||||
```
|
||||
|
||||
generates
|
||||
@ -317,7 +317,7 @@ generates
|
||||
* - `user`
|
||||
* - `category`
|
||||
*/
|
||||
class m160328_040430_create_post extends Migration
|
||||
class m160328_040430_create_post_table extends Migration
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -422,13 +422,13 @@ column named `author_id` with a foreign key to the `user` table while
|
||||
### Drop Table
|
||||
|
||||
```php
|
||||
yii migrate/create drop_post --fields="title:string(12):notNull:unique,body:text"
|
||||
yii migrate/create drop_post_table --fields="title:string(12):notNull:unique,body:text"
|
||||
```
|
||||
|
||||
generates
|
||||
|
||||
```php
|
||||
class m150811_220037_drop_post extends Migration
|
||||
class m150811_220037_drop_post_table extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
@ -448,19 +448,19 @@ class m150811_220037_drop_post extends Migration
|
||||
|
||||
### Add Column
|
||||
|
||||
If the migration name is of the form `add_xxx_to_yyy` then the file content would contain `addColumn` and `dropColumn`
|
||||
statements necessary.
|
||||
If the migration name is of the form `add_xxx_column_to_yyy_table` then the file
|
||||
content would contain `addColumn` and `dropColumn` statements necessary.
|
||||
|
||||
To add column:
|
||||
|
||||
```php
|
||||
yii migrate/create add_position_to_post --fields="position:integer"
|
||||
yii migrate/create add_position_column_to_post_table --fields="position:integer"
|
||||
```
|
||||
|
||||
generates
|
||||
|
||||
```php
|
||||
class m150811_220037_add_position_to_post extends Migration
|
||||
class m150811_220037_add_position_column_to_post_table extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
@ -476,17 +476,17 @@ class m150811_220037_add_position_to_post extends Migration
|
||||
|
||||
### Drop Column
|
||||
|
||||
If the migration name is of the form `drop_xxx_from_yyy` then the file content would contain `addColumn` and `dropColumn`
|
||||
statements necessary.
|
||||
If the migration name is of the form `drop_xxx_column_from_yyy_table` then
|
||||
the file content would contain `addColumn` and `dropColumn` statements necessary.
|
||||
|
||||
```php
|
||||
yii migrate/create drop_position_from_post --fields="position:integer"
|
||||
yii migrate/create drop_position_column_from_post_table --fields="position:integer"
|
||||
```
|
||||
|
||||
generates
|
||||
|
||||
```php
|
||||
class m150811_220037_drop_position_from_post extends Migration
|
||||
class m150811_220037_drop_position_column_from_post_table extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
@ -502,11 +502,11 @@ class m150811_220037_drop_position_from_post extends Migration
|
||||
|
||||
### Add Junction Table
|
||||
|
||||
If the migration name is in if the form of `create_junction_xxx_and_yyy` then code necessary to create junction table
|
||||
will be generated.
|
||||
If the migration name is of the form `create_junction_table_for_xxx_and_yyy_tables` or `create_junction_xxx_and_yyy_tables`
|
||||
then code necessary to create junction table will be generated.
|
||||
|
||||
```php
|
||||
yii migrate/create create_junction_post_and_tag --fields="created_at:dateTime"
|
||||
yii migrate/create create_junction_table_for_post_and_tag_tables --fields="created_at:dateTime"
|
||||
```
|
||||
|
||||
generates
|
||||
@ -519,7 +519,7 @@ generates
|
||||
* - `post`
|
||||
* - `tag`
|
||||
*/
|
||||
class m160328_041642_create_junction_post_and_tag extends Migration
|
||||
class m160328_041642_create_junction_table_for_post_and_tag_tables extends Migration
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
|
Reference in New Issue
Block a user