mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Document the fact you can add_index on new columns
This commit is contained in:
parent
14254d82a9
commit
1badf20497
1 changed files with 19 additions and 1 deletions
|
@ -150,7 +150,25 @@ class AddPartNumberToProducts < ActiveRecord::Migration
|
|||
end
|
||||
```
|
||||
|
||||
Similarly,
|
||||
If you'd like to add an index on the new column, you can do that as well:
|
||||
|
||||
```bash
|
||||
$ rails generate migration AddPartNumberToProducts part_number:string:index
|
||||
```
|
||||
|
||||
will generate
|
||||
|
||||
```ruby
|
||||
class AddPartNumberToProducts < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :products, :part_number, :string
|
||||
add_index :products, :part_number
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
Similarly, you can generate a migration to remove a column from the command line:
|
||||
|
||||
```bash
|
||||
$ rails generate migration RemovePartNumberFromProducts part_number:string
|
||||
|
|
Loading…
Reference in a new issue