# BaseMigrateController

> BaseMigrateController is the base class for migrate controllers.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [console](/docs/api/yii/console/index.md) › [controllers](/docs/api/yii/console/controllers/index.md) › BaseMigrateController

| abstract class | `yii\console\controllers\BaseMigrateController` |
| --- | --- |
| Extends | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) » [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) » [`yii\base\Component`](/docs/api/yii/base/component/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\ViewContextInterface`](/docs/api/yii/base/viewcontextinterface/index.md), [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/console/controllers/BaseMigrateController.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/console/controllers/BaseMigrateController.php#L34) |

1 subclass:

- [`MigrateController`](/docs/api/yii/console/controllers/migratecontroller/index.md)

BaseMigrateController is the base class for migrate controllers.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-action"></span>[`$action`](/docs/api/yii/base/controller/index.md#property-action) | [`yii\base\Action`](/docs/api/yii/base/action/index.md)`<static>\|null` | The action that is currently being executed. Default: `null`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`yii\base\Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="property-color"></span>[`$color`](/docs/api/yii/console/controller/index.md#property-color) | `bool\|null` | Whether to enable ANSI color in the output. Default: `null`. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| [`$compact`](#property-compact) | `bool` | Indicates whether the console output should be compacted. Default: `false`. Available since 2.0.13. | `BaseMigrateController` |
| <span id="property-defaultAction"></span>`$defaultAction` | `string` | The default command action. Default: `'up'`. | `BaseMigrateController` |
| <span id="property-help"></span>[`$help`](/docs/api/yii/console/controller/index.md#property-help) | `bool` | Whether to display help information about current command. Default: `false`. Available since 2.0.10. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="property-helpSummary"></span>[`$helpSummary`](/docs/api/yii/console/controller/index.md#property-helpSummary) read-only | `string` | The one-line short summary describing this controller. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="property-id"></span>[`$id`](/docs/api/yii/base/controller/index.md#property-id) | `string` | The ID of this controller. Default: `null`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-interactive"></span>[`$interactive`](/docs/api/yii/console/controller/index.md#property-interactive) | `bool` | Whether to run the command interactively. Default: `true`. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="property-layout"></span>[`$layout`](/docs/api/yii/base/controller/index.md#property-layout) | `string\|null\|false` | The name of the layout to be applied to this controller's views. Default: `null`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| [`$migrationNamespaces`](#property-migrationNamespaces) | `array` | List of namespaces containing the migration classes. Default: `[]`. Available since 2.0.10. | `BaseMigrateController` |
| [`$migrationPath`](#property-migrationPath) | `string\|array\|null` | The directory containing the migration classes. Default: `['@app/migrations']`. | `BaseMigrateController` |
| <span id="property-module"></span>[`$module`](/docs/api/yii/base/controller/index.md#property-module) | `yii\base\T` | The module that this controller belongs to. Default: `null`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-modules"></span>[`$modules`](/docs/api/yii/base/controller/index.md#property-modules) read-only | [`yii\base\Module`](/docs/api/yii/base/module/index.md)`[]` | All ancestor modules that this controller is located within. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| [`$newFileMode`](#property-newFileMode) | `int\|null` | The permission to be set for newly generated migration files. Default: `null`. Available since 2.0.43. | `BaseMigrateController` |
| [`$newFileOwnership`](#property-newFileOwnership) | `string\|int\|null` | The user and/or group ownership to be set for newly generated migration files. Default: `null`. Available since 2.0.43. | `BaseMigrateController` |
| <span id="property-passedOptions"></span>[`$passedOptions`](/docs/api/yii/console/controller/index.md#property-passedOptions) read-only | `array` | The names of the options passed during execution. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="property-passedOptionValues"></span>[`$passedOptionValues`](/docs/api/yii/console/controller/index.md#property-passedOptionValues) read-only | `array` | The properties corresponding to the passed options. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="property-request"></span>[`$request`](/docs/api/yii/console/controller/index.md#property-request) | [`yii\console\Request`](/docs/api/yii/console/request/index.md) | The request object. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="property-response"></span>[`$response`](/docs/api/yii/console/controller/index.md#property-response) | [`yii\console\Response`](/docs/api/yii/console/response/index.md) | The response object. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="property-route"></span>[`$route`](/docs/api/yii/base/controller/index.md#property-route) read-only | `string` | The route (module ID, controller ID and action ID) of the current request. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-silentExitOnException"></span>[`$silentExitOnException`](/docs/api/yii/console/controller/index.md#property-silentExitOnException) | `bool\|null` | If true - script finish with `ExitCode::OK` in case of exception. false - `ExitCode::UNSPECIFIED_ERROR`. Default: `null`. Available since 2.0.36. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| [`$templateFile`](#property-templateFile) | `string` | The template file for generating new migrations. Default: `null`. | `BaseMigrateController` |
| <span id="property-uniqueId"></span>[`$uniqueId`](/docs/api/yii/base/controller/index.md#property-uniqueId) read-only | `string` | The controller ID that is prefixed with the module ID (if any). | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-view"></span>[`$view`](/docs/api/yii/base/controller/index.md#property-view) | [`yii\base\View`](/docs/api/yii/base/view/index.md)`\|`[`yii\web\View`](/docs/api/yii/web/view/index.md) | The view object that can be used to render views or view files. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-viewPath"></span>[`$viewPath`](/docs/api/yii/base/controller/index.md#property-viewPath) | `string` | The directory containing the view files for this controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/controller/index.md#method-__construct) |  | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/component/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__clone"></span>[`__clone()`](/docs/api/yii/base/component/index.md#method-__clone) | This method is called after the object is created by cloning an existing one. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/component/index.md#method-__get) | Returns the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/component/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/component/index.md#method-__set) | Sets the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/component/index.md#method-__unset) | Sets a component property to be null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`actionCreate()`](#method-actionCreate) | Creates a new migration. | `BaseMigrateController` |
| [`actionDown()`](#method-actionDown) | Downgrades the application by reverting old migrations. | `BaseMigrateController` |
| [`actionFresh()`](#method-actionFresh) | Drops all tables and related constraints. Starts the migration from the beginning. | `BaseMigrateController` |
| [`actionHistory()`](#method-actionHistory) | Displays the migration history. | `BaseMigrateController` |
| [`actionMark()`](#method-actionMark) | Modifies the migration history to the specified version. | `BaseMigrateController` |
| [`actionNew()`](#method-actionNew) | Displays the un-applied new migrations. | `BaseMigrateController` |
| [`actionRedo()`](#method-actionRedo) | Redoes the last few migrations. | `BaseMigrateController` |
| <span id="method-actions"></span>[`actions()`](/docs/api/yii/base/controller/index.md#method-actions) | Declares external actions for the controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| [`actionTo()`](#method-actionTo) | Upgrades or downgrades till the specified version. | `BaseMigrateController` |
| [`actionUp()`](#method-actionUp) | Upgrades the application by applying new migrations. | `BaseMigrateController` |
| <span id="method-afterAction"></span>[`afterAction()`](/docs/api/yii/base/controller/index.md#method-afterAction) | This method is invoked right after an action is executed. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-ansiFormat"></span>[`ansiFormat()`](/docs/api/yii/console/controller/index.md#method-ansiFormat) | Formats a string with ANSI codes. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-attachBehavior"></span>[`attachBehavior()`](/docs/api/yii/base/component/index.md#method-attachBehavior) | Attaches a behavior to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehaviors"></span>[`attachBehaviors()`](/docs/api/yii/base/component/index.md#method-attachBehaviors) | Attaches a list of behaviors to the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`beforeAction()`](#method-beforeAction) | This method is invoked right before an action is to be executed (after all possible filters.) It checks the existence of the [`$migrationPath`](/docs/api/yii/console/controllers/basemigratecontroller/index.md#property-migrationPath). | `BaseMigrateController` |
| <span id="method-behaviors"></span>[`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) | Returns a list of behaviors that this component should behave as. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-bindActionParams"></span>[`bindActionParams()`](/docs/api/yii/console/controller/index.md#method-bindActionParams) | Binds the parameters to the action. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/component/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/component/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-confirm"></span>[`confirm()`](/docs/api/yii/console/controller/index.md#method-confirm) | Asks user to confirm by typing y or n. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-createAction"></span>[`createAction()`](/docs/api/yii/base/controller/index.md#method-createAction) | Creates an action based on the given action ID. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-detachBehavior"></span>[`detachBehavior()`](/docs/api/yii/base/component/index.md#method-detachBehavior) | Detaches a behavior from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-detachBehaviors"></span>[`detachBehaviors()`](/docs/api/yii/base/component/index.md#method-detachBehaviors) | Detaches all behaviors from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-ensureBehaviors"></span>[`ensureBehaviors()`](/docs/api/yii/base/component/index.md#method-ensureBehaviors) | Makes sure that the behaviors declared in [`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) are attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-findLayoutFile"></span>[`findLayoutFile()`](/docs/api/yii/base/controller/index.md#method-findLayoutFile) | Finds the applicable layout file. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-getActionArgsHelp"></span>[`getActionArgsHelp()`](/docs/api/yii/console/controller/index.md#method-getActionArgsHelp) | Returns the help information for the anonymous arguments for the action. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getActionHelp"></span>[`getActionHelp()`](/docs/api/yii/console/controller/index.md#method-getActionHelp) | Returns the detailed help information for the specified action. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getActionHelpSummary"></span>[`getActionHelpSummary()`](/docs/api/yii/console/controller/index.md#method-getActionHelpSummary) | Returns a one-line short summary describing the specified action. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getActionOptionsHelp"></span>[`getActionOptionsHelp()`](/docs/api/yii/console/controller/index.md#method-getActionOptionsHelp) | Returns the help information for the options for the action. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getBehavior"></span>[`getBehavior()`](/docs/api/yii/base/component/index.md#method-getBehavior) | Returns the named behavior object. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehaviors"></span>[`getBehaviors()`](/docs/api/yii/base/component/index.md#method-getBehaviors) | Returns all behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getHelp"></span>[`getHelp()`](/docs/api/yii/console/controller/index.md#method-getHelp) | Returns help information for this controller. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getHelpSummary"></span>[`getHelpSummary()`](/docs/api/yii/console/controller/index.md#method-getHelpSummary) | Returns one-line short summary describing this controller. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getModules"></span>[`getModules()`](/docs/api/yii/base/controller/index.md#method-getModules) | Returns all ancestor modules of this controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-getOptionValues"></span>[`getOptionValues()`](/docs/api/yii/console/controller/index.md#method-getOptionValues) | Returns properties corresponding to the options for the action id Child classes may override this method to specify possible properties. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getPassedOptions"></span>[`getPassedOptions()`](/docs/api/yii/console/controller/index.md#method-getPassedOptions) | Returns the names of valid options passed during execution. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getPassedOptionValues"></span>[`getPassedOptionValues()`](/docs/api/yii/console/controller/index.md#method-getPassedOptionValues) | Returns the properties corresponding to the passed options. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getRoute"></span>[`getRoute()`](/docs/api/yii/base/controller/index.md#method-getRoute) | Returns the route of the current request. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-getUniqueId"></span>[`getUniqueId()`](/docs/api/yii/base/controller/index.md#method-getUniqueId) | Returns the unique ID of the controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-getView"></span>[`getView()`](/docs/api/yii/base/controller/index.md#method-getView) | Returns the view object that can be used to render views or view files. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-getViewPath"></span>[`getViewPath()`](/docs/api/yii/base/controller/index.md#method-getViewPath) | Returns the directory containing view files for this controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-hasEventHandlers"></span>[`hasEventHandlers()`](/docs/api/yii/base/component/index.md#method-hasEventHandlers) | Returns a value indicating whether there is any handler attached to the named event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/component/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/component/index.md#method-hasProperty) | Returns a value indicating whether a property is defined for this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/base/controller/index.md#method-init) | Initializes the object. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-isColorEnabled"></span>[`isColorEnabled()`](/docs/api/yii/console/controller/index.md#method-isColorEnabled) | Returns a value indicating whether ANSI color is enabled. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-on"></span>[`on()`](/docs/api/yii/base/component/index.md#method-on) | Attaches an event handler to an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-optionAliases"></span>[`optionAliases()`](/docs/api/yii/console/controller/index.md#method-optionAliases) | Returns option alias names. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| [`options()`](#method-options) | Returns the names of valid options for the action (id) An option requires the existence of a public member variable whose name is the option name. | `BaseMigrateController` |
| <span id="method-prompt"></span>[`prompt()`](/docs/api/yii/console/controller/index.md#method-prompt) | Prompts the user for input and validates it. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-render"></span>[`render()`](/docs/api/yii/base/controller/index.md#method-render) | Renders a view and applies layout if available. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-renderContent"></span>[`renderContent()`](/docs/api/yii/base/controller/index.md#method-renderContent) | Renders a static string by applying a layout. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-renderFile"></span>[`renderFile()`](/docs/api/yii/base/controller/index.md#method-renderFile) | Renders a view file. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-renderPartial"></span>[`renderPartial()`](/docs/api/yii/base/controller/index.md#method-renderPartial) | Renders a view without applying layout. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-run"></span>[`run()`](/docs/api/yii/base/controller/index.md#method-run) | Runs a request specified in terms of a route. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-runAction"></span>[`runAction()`](/docs/api/yii/console/controller/index.md#method-runAction) | Runs an action with the specified action ID and parameters. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-select"></span>[`select()`](/docs/api/yii/console/controller/index.md#method-select) | Gives the user an option to choose from. Giving '?' as an input will show a list of options to choose from and their explanations. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-setView"></span>[`setView()`](/docs/api/yii/base/controller/index.md#method-setView) | Sets the view object to be used by this controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-setViewPath"></span>[`setViewPath()`](/docs/api/yii/base/controller/index.md#method-setViewPath) | Sets the directory that contains the view files. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-stderr"></span>[`stderr()`](/docs/api/yii/console/controller/index.md#method-stderr) | Prints a string to STDERR. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-stdout"></span>[`stdout()`](/docs/api/yii/console/controller/index.md#method-stdout) | Prints a string to STDOUT. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-trigger"></span>[`trigger()`](/docs/api/yii/base/component/index.md#method-trigger) | Triggers an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`addMigrationHistory()`](#method-addMigrationHistory) protected abstract | Adds new migration entry to the history. | `BaseMigrateController` |
| <span id="method-bindInjectedParams"></span>[`bindInjectedParams()`](/docs/api/yii/base/controller/index.md#method-bindInjectedParams) protected final | Fills parameters based on types and names in action method signature. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| [`createMigration()`](#method-createMigration) protected | Creates a new migration instance. | `BaseMigrateController` |
| [`generateMigrationSourceCode()`](#method-generateMigrationSourceCode) protected | Generates new migration source PHP code. | `BaseMigrateController` |
| <span id="method-getActionMethodReflection"></span>[`getActionMethodReflection()`](/docs/api/yii/console/controller/index.md#method-getActionMethodReflection) protected |  | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| [`getMigrationHistory()`](#method-getMigrationHistory) protected abstract | Returns the migration history. | `BaseMigrateController` |
| [`getMigrationNameLimit()`](#method-getMigrationNameLimit) protected | Return the maximum name length for a migration. | `BaseMigrateController` |
| [`getNewMigrations()`](#method-getNewMigrations) protected | Returns the migrations that are not applied. | `BaseMigrateController` |
| [`includeMigrationFile()`](#method-includeMigrationFile) protected | Includes the migration file for a given migration class name. | `BaseMigrateController` |
| [`migrateDown()`](#method-migrateDown) protected | Downgrades with the specified migration class. | `BaseMigrateController` |
| [`migrateToTime()`](#method-migrateToTime) protected | Migrates to the specified apply time in the past. | `BaseMigrateController` |
| [`migrateToVersion()`](#method-migrateToVersion) protected | Migrates to the certain version. | `BaseMigrateController` |
| [`migrateUp()`](#method-migrateUp) protected | Upgrades with the specified migration class. | `BaseMigrateController` |
| <span id="method-parseDocCommentDetail"></span>[`parseDocCommentDetail()`](/docs/api/yii/console/controller/index.md#method-parseDocCommentDetail) protected | Returns full description from the docblock. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-parseDocCommentSummary"></span>[`parseDocCommentSummary()`](/docs/api/yii/console/controller/index.md#method-parseDocCommentSummary) protected | Returns the first line of docblock. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-parseDocCommentTags"></span>[`parseDocCommentTags()`](/docs/api/yii/console/controller/index.md#method-parseDocCommentTags) protected | Parses the comment block into tags. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| [`removeMigrationHistory()`](#method-removeMigrationHistory) protected abstract | Removes existing migration from the history. | `BaseMigrateController` |
| [`truncateDatabase()`](#method-truncateDatabase) protected | Truncates the database. | `BaseMigrateController` |

## Events

| Event | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="event-EVENT_BEFORE_ACTION"></span>[`EVENT_BEFORE_ACTION`](/docs/api/yii/base/controller/index.md#event-EVENT_BEFORE_ACTION) | [`yii\base\ActionEvent`](/docs/api/yii/base/actionevent/index.md) | An event raised right before executing a controller action. Event name: `'beforeAction'`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="event-EVENT_AFTER_ACTION"></span>[`EVENT_AFTER_ACTION`](/docs/api/yii/base/controller/index.md#event-EVENT_AFTER_ACTION) | [`yii\base\ActionEvent`](/docs/api/yii/base/actionevent/index.md) | An event raised right after executing a controller action. Event name: `'afterAction'`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-BASE_MIGRATION"></span>`BASE_MIGRATION` | `'m000000_000000_base'` | The name of the dummy migration that marks the beginning of the whole migration history. | `BaseMigrateController` |

## Property details

### $compact <span id="property-compact"></span>

```php
public bool $compact = false
```

Indicates whether the console output should be compacted.

If this is set to true, the individual commands ran within the migration will not be output to the console.
Default is false, in other words the output is fully verbose by default.

**Since**

2.0.13

### $migrationNamespaces <span id="property-migrationNamespaces"></span>

```php
public array $migrationNamespaces = []
```

List of namespaces containing the migration classes.

Migration namespaces should be resolvable as a [path alias](/docs/guide/concept-aliases/index.md) if prefixed with `@`, e.g. if you specify
the namespace `app\migrations`, the code `Yii::getAlias('@app/migrations')` should be able to return
the file path to the directory this namespace refers to.
This corresponds with the [autoloading conventions](/docs/guide/concept-autoloading/index.md) of Yii.

For example:

```
[
    'app\migrations',
    'some\extension\migrations',
]
```

**Since**

2.0.10

### $migrationPath <span id="property-migrationPath"></span>

```php
public string|array|null $migrationPath = ['@app/migrations']
```

The directory containing the migration classes.

This can be either
a [path alias](/docs/guide/concept-aliases/index.md) or a directory path.

Migration classes located at this path should be declared without a namespace.
Use [`$migrationNamespaces`](/docs/api/yii/console/controllers/basemigratecontroller/index.md#property-migrationNamespaces) property in case you are using namespaced migrations.

If you have set up [`$migrationNamespaces`](/docs/api/yii/console/controllers/basemigratecontroller/index.md#property-migrationNamespaces), you may set this field to `null` in order
to disable usage of migrations that are not namespaced.

Since version 2.0.12 you may also specify an array of migration paths that should be searched for
migrations to load. This is mainly useful to support old extensions that provide migrations
without namespace and to adopt the new feature of namespaced migrations while keeping existing migrations.

In general, to load migrations from different locations, [`$migrationNamespaces`](/docs/api/yii/console/controllers/basemigratecontroller/index.md#property-migrationNamespaces) is the preferable solution
as the migration name contains the origin of the migration in the history, which is not the case when
using multiple migration paths.

### $newFileMode <span id="property-newFileMode"></span>

```php
public int|null $newFileMode = null
```

The permission to be set for newly generated migration files.

This value will be used by PHP chmod() function. No umask will be applied.
If not set, the permission will be determined by the current environment.

**Since**

2.0.43

### $newFileOwnership <span id="property-newFileOwnership"></span>

```php
public string|int|null $newFileOwnership = null
```

The user and/or group ownership to be set for newly generated migration files.

If not set, the ownership will be determined by the current environment.

**Since**

2.0.43

### $templateFile <span id="property-templateFile"></span>

```php
public string $templateFile = null
```

The template file for generating new migrations.

This can be either a [path alias](/docs/guide/concept-aliases/index.md) (e.g. "@app/migrations/template.php")
or a file path.

## Method details

### actionCreate() <span id="method-actionCreate"></span>

```php
public function actionCreate(string $name): mixed
```

Creates a new migration.

This command creates a new migration using the available migration template.
After using this command, developers should modify the created migration
skeleton by filling up the actual migration logic.

```
yii migrate/create create_user_table
```

In order to generate a namespaced migration, you should specify a namespace before the migration's name.
Note that backslash (`\`) is usually considered a special character in the shell, so you need to escape it
properly to avoid shell errors or incorrect behavior.
For example:

```
yii migrate/create app\\migrations\\createUserTable
```

In case [`$migrationPath`](/docs/api/yii/console/controllers/basemigratecontroller/index.md#property-migrationPath) is not set and no namespace is provided, the first entry of [`$migrationNamespaces`](/docs/api/yii/console/controllers/basemigratecontroller/index.md#property-migrationNamespaces) will be used.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name of the new migration. This should only contain letters, digits, underscores and/or backslashes. Note: If the migration name is of a special form, for example create_xxx or drop_xxx, then the generated migration file will contain extra code, in this case for creating/dropping tables. |

**Returns**

`mixed`

**Throws**

- [`yii\console\Exception`](/docs/api/yii/console/exception/index.md): if the name argument is invalid.

### actionDown() <span id="method-actionDown"></span>

```php
public function actionDown(int|string $limit = 1): int
```

Downgrades the application by reverting old migrations.

For example,

```
yii migrate/down     # revert the last migration
yii migrate/down 3   # revert the last 3 migrations
yii migrate/down all # revert all migrations
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$limit` | `int\|string` | The number of migrations to be reverted. Defaults to 1, meaning the last applied migration will be reverted. When value is "all", all migrations will be reverted. |

**Returns**

`int`: The status of the action execution. 0 means normal, other values mean abnormal.

**Throws**

- [`yii\console\Exception`](/docs/api/yii/console/exception/index.md): if the number of the steps specified is less than 1.

### actionFresh() <span id="method-actionFresh"></span>

```php
public function actionFresh(): mixed
```

Drops all tables and related constraints. Starts the migration from the beginning.

```
yii migrate/fresh
```

**Returns**

`mixed`

**Since**

2.0.13

### actionHistory() <span id="method-actionHistory"></span>

```php
public function actionHistory(int|string $limit = 10): mixed
```

Displays the migration history.

This command will show the list of migrations that have been applied
so far. For example,

```
yii migrate/history     # showing the last 10 migrations
yii migrate/history 5   # showing the last 5 migrations
yii migrate/history all # showing the whole history
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$limit` | `int\|string` | The maximum number of migrations to be displayed. If it is "all", the whole migration history will be displayed. |

**Returns**

`mixed`

**Throws**

- [`yii\console\Exception`](/docs/api/yii/console/exception/index.md): if invalid limit value passed

### actionMark() <span id="method-actionMark"></span>

```php
public function actionMark(string $version): int
```

Modifies the migration history to the specified version.

No actual migration will be performed.

```
yii migrate/mark 101129_185401                        # using timestamp
yii migrate/mark m101129_185401_create_user_table     # using full name
yii migrate/mark app\migrations\M101129185401CreateUser # using full namespace name
yii migrate/mark m000000_000000_base # reset the complete migration history
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$version` | `string` | The version at which the migration history should be marked. This can be either the timestamp or the full name of the migration. You may specify the name `m000000_000000_base` to set the migration history to a state where no migration has been applied. |

**Returns**

`int`: CLI exit code

**Throws**

- [`yii\console\Exception`](/docs/api/yii/console/exception/index.md): if the version argument is invalid or the version cannot be found.

### actionNew() <span id="method-actionNew"></span>

```php
public function actionNew(int|string $limit = 10): mixed
```

Displays the un-applied new migrations.

This command will show the new migrations that have not been applied.
For example,

```
yii migrate/new     # showing the first 10 new migrations
yii migrate/new 5   # showing the first 5 new migrations
yii migrate/new all # showing all new migrations
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$limit` | `int\|string` | The maximum number of new migrations to be displayed. If it is `all`, all available new migrations will be displayed. |

**Returns**

`mixed`

**Throws**

- [`yii\console\Exception`](/docs/api/yii/console/exception/index.md): if invalid limit value passed

### actionRedo() <span id="method-actionRedo"></span>

```php
public function actionRedo(int|string $limit = 1): int
```

Redoes the last few migrations.

This command will first revert the specified migrations, and then apply
them again. For example,

```
yii migrate/redo     # redo the last applied migration
yii migrate/redo 3   # redo the last 3 applied migrations
yii migrate/redo all # redo all migrations
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$limit` | `int\|string` | The number of migrations to be redone. Defaults to 1, meaning the last applied migration will be redone. When equals "all", all migrations will be redone. |

**Returns**

`int`: The status of the action execution. 0 means normal, other values mean abnormal.

**Throws**

- [`yii\console\Exception`](/docs/api/yii/console/exception/index.md): if the number of the steps specified is less than 1.

### actionTo() <span id="method-actionTo"></span>

```php
public function actionTo(string $version): mixed
```

Upgrades or downgrades till the specified version.

Can also downgrade versions to the certain apply time in the past by providing
a UNIX timestamp or a string parseable by the strtotime() function. This means
that all the versions applied after the specified certain time would be reverted.

This command will first revert the specified migrations, and then apply
them again. For example,

```
yii migrate/to 101129_185401                          # using timestamp
yii migrate/to m101129_185401_create_user_table       # using full name
yii migrate/to 1392853618                             # using UNIX timestamp
yii migrate/to "2014-02-15 13:00:50"                  # using strtotime() parseable string
yii migrate/to app\migrations\M101129185401CreateUser # using full namespace name
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$version` | `string` | Either the version name or the certain time value in the past that the application should be migrated to. This can be either the timestamp, the full name of the migration, the UNIX timestamp, or the parseable datetime string. |

**Returns**

`mixed`

**Throws**

- [`yii\console\Exception`](/docs/api/yii/console/exception/index.md): if the version argument is invalid.

### actionUp() <span id="method-actionUp"></span>

```php
public function actionUp(int $limit = 0): int
```

Upgrades the application by applying new migrations.

For example,

```
yii migrate     # apply all new migrations
yii migrate 3   # apply the first 3 new migrations
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$limit` | `int` | The number of new migrations to be applied. If 0, it means applying all available new migrations. |

**Returns**

`int`: The status of the action execution. 0 means normal, other values mean abnormal.

### beforeAction() <span id="method-beforeAction"></span>

```php
public function beforeAction(yii\base\Action<static> $action): bool
```

This method is invoked right before an action is to be executed (after all possible filters.)
It checks the existence of the [`$migrationPath`](/docs/api/yii/console/controllers/basemigratecontroller/index.md#property-migrationPath).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$action` | [`yii\base\Action`](/docs/api/yii/base/action/index.md)`<static>` | The action to be executed. |

**Returns**

`bool`: Whether the action should continue to be executed.

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if directory specified in migrationPath doesn't exist and action isn't "create".

### options() <span id="method-options"></span>

```php
public function options(mixed $actionID): string[]
```

Returns the names of valid options for the action (id)
An option requires the existence of a public member variable whose
name is the option name.

Child classes may override this method to specify possible options.

Note that the values setting via options are not available
until [`beforeAction()`](/docs/api/yii/console/controllers/basemigratecontroller/index.md#method-beforeAction) is being called.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$actionID` | `mixed` | The action id of the current request |

**Returns**

`string[]`: The names of the options valid for the action

### addMigrationHistory() <span id="method-addMigrationHistory"></span>

```php
abstract protected function addMigrationHistory(string $version): mixed
```

Adds new migration entry to the history.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$version` | `string` | Migration version name. |

**Returns**

`mixed`

### createMigration() <span id="method-createMigration"></span>

```php
protected function createMigration(string $class): yii\db\MigrationInterface
```

Creates a new migration instance.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$class` | `string` | The migration class name |

**Returns**

[`yii\db\MigrationInterface`](/docs/api/yii/db/migrationinterface/index.md): The migration instance

### generateMigrationSourceCode() <span id="method-generateMigrationSourceCode"></span>

```php
protected function generateMigrationSourceCode(array $params): string
```

Generates new migration source PHP code.

Child class may override this method, adding extra logic or variation to the process.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$params` | `array` | Generation parameters, usually following parameters are present: - name: string migration base name - className: string migration class name |

**Returns**

`string`: Generated PHP code.

**Since**

2.0.8

### getMigrationHistory() <span id="method-getMigrationHistory"></span>

```php
abstract protected function getMigrationHistory(int|null $limit): array
```

Returns the migration history.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$limit` | `int\|null` | The maximum number of records in the history to be returned. `null` for "no limit". |

**Returns**

`array`: The migration history

### getMigrationNameLimit() <span id="method-getMigrationNameLimit"></span>

```php
protected function getMigrationNameLimit(): int|null
```

Return the maximum name length for a migration.

Subclasses may override this method to define a limit.

**Returns**

`int|null`: The maximum name length for a migration or `null` if no limit applies.

**Since**

2.0.13

### getNewMigrations() <span id="method-getNewMigrations"></span>

```php
protected function getNewMigrations(): array
```

Returns the migrations that are not applied.

**Returns**

`array`: List of new migrations

### includeMigrationFile() <span id="method-includeMigrationFile"></span>

```php
protected function includeMigrationFile(string $class): mixed
```

Includes the migration file for a given migration class name.

This function will do nothing on namespaced migrations, which are loaded by
autoloading automatically. It will include the migration file, by searching
[`$migrationPath`](/docs/api/yii/console/controllers/basemigratecontroller/index.md#property-migrationPath) for classes without namespace.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$class` | `string` | The migration class name. |

**Returns**

`mixed`

**Since**

2.0.12

### migrateDown() <span id="method-migrateDown"></span>

```php
protected function migrateDown(string $class): bool
```

Downgrades with the specified migration class.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$class` | `string` | The migration class name |

**Returns**

`bool`: Whether the migration is successful

### migrateToTime() <span id="method-migrateToTime"></span>

```php
protected function migrateToTime(int $time): mixed
```

Migrates to the specified apply time in the past.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$time` | `int` | UNIX timestamp value. |

**Returns**

`mixed`

### migrateToVersion() <span id="method-migrateToVersion"></span>

```php
protected function migrateToVersion(string $version): int
```

Migrates to the certain version.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$version` | `string` | Name in the full format. |

**Returns**

`int`: CLI exit code

**Throws**

- [`yii\console\Exception`](/docs/api/yii/console/exception/index.md): if the provided version cannot be found.

### migrateUp() <span id="method-migrateUp"></span>

```php
protected function migrateUp(string $class): bool
```

Upgrades with the specified migration class.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$class` | `string` | The migration class name |

**Returns**

`bool`: Whether the migration is successful

### removeMigrationHistory() <span id="method-removeMigrationHistory"></span>

```php
abstract protected function removeMigrationHistory(string $version): mixed
```

Removes existing migration from the history.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$version` | `string` | Migration version name. |

**Returns**

`mixed`

### truncateDatabase() <span id="method-truncateDatabase"></span>

```php
protected function truncateDatabase(): mixed
```

Truncates the database.

This method should be overwritten in subclasses to implement the task of clearing the database.

**Returns**

`mixed`

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): if not overridden

**Since**

2.0.13