Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
f526cc7a
Commit
f526cc7a
authored
Aug 24, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more doc [skip ci]
parent
f5ee8e45
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
8 deletions
+11
-8
db-migrations.md
docs/guide/db-migrations.md
+11
-8
No files found.
docs/guide/db-migrations.md
View file @
f526cc7a
...
...
@@ -350,9 +350,10 @@ yii migrate --db=db2
The above command will apply
*all*
migrations found in the default migration path to the
`db2`
database.
If your application works with multiple databases, some migrations should be applied to one database while
some others should be applied to another database. In this case, it is recommended that you create a base
migration class for each different database and override the
[
[yii\db\Migration::init()
]
] method like the following,
If your application works with multiple databases, it is possible that some migrations should be applied
to one database while some others should be applied to another database. In this case, it is recommended that
you create a base migration class for each different database and override the
[
[yii\db\Migration::init()
]
]
method like the following,
```
php
public
function
init
()
...
...
@@ -362,13 +363,13 @@ public function init()
}
```
If a migration needs to be applied to one database, you create a migration class by extending
from the corresponding
base migration class.
To create a migration that should be applied to a particular database, simply extend
from the corresponding
base migration class.
Now if you run the
`yii migrate`
command, each migration will be applied to its corresponding database.
Now if you run the
`yii migrate`
command, each migration will be applied to the corresponding database.
Because each migration has harcoded the DB connection, the
`--db`
option of the
`migrate`
command will have no effect
.
> Info: Because each migration uses hardcoded DB connection, the `--db` option of the `migrate` command will
have no effect. Also note that the migration history will be stored in the default
`db`
database
.
If you
still
want to support changing DB connection via the
`--db`
option, you may take the following alternative
If you want to support changing DB connection via the
`--db`
option, you may take the following alternative
approach to work with multiple databases.
For each database, create a migration path and save all corresponding migration classes there. To apply migrations,
...
...
@@ -379,3 +380,5 @@ yii migrate --migrationPath=@app/migrations/db1 --db=db1
yii migrate --migrationPath=@app/migrations/db2 --db=db2
...
```
> Info: The above approach stores the migration history in different databases specified via the `--db` option.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment