Skip to content

Commit 07ce474

Browse files
authored
Merge pull request rails#53502 from tumes/update-migration-modifier-info
Revise docs to reflect ! shortcut for generated migrations [ci skip]
2 parents 56d543f + 9d674e5 commit 07ce474

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

guides/source/active_record_migrations.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,23 @@ class AddDetailsToProducts < ActiveRecord::Migration[8.1]
375375
end
376376
```
377377

378+
`NOT NULL` constraints can be imposed from the command line using the `!`
379+
shortcut:
380+
381+
```bash
382+
$ bin/rails generate migration AddEmailToUsers email:string!
383+
```
384+
385+
will produce this migration
386+
387+
```ruby
388+
class AddEmailToUsers < ActiveRecord::Migration[8.1]
389+
def change
390+
add_column :users, :email, :string, null: false
391+
end
392+
end
393+
```
394+
378395
TIP: For further help with generators, run `bin/rails generate --help`.
379396
Alternatively, you can also run `bin/rails generate model --help` or `bin/rails
380397
generate migration --help` for help with specific generators.
@@ -692,8 +709,7 @@ They need to be added separately using `add_index`.
692709
Some adapters may support additional options; see the adapter specific API docs
693710
for further information.
694711

695-
NOTE: `null` and `default` cannot be specified via command line when generating
696-
migrations.
712+
NOTE: `default` cannot be specified via command line when generating migrations.
697713

698714
### References
699715

0 commit comments

Comments
 (0)