提交 fd495a8d 编写于 作者: X Xavier Noria

updates a migration example in the Getting Started guide [ci skip]

Closes #20705.
上级 6a6c4c45
...@@ -1546,8 +1546,6 @@ class CreateComments < ActiveRecord::Migration ...@@ -1546,8 +1546,6 @@ class CreateComments < ActiveRecord::Migration
create_table :comments do |t| create_table :comments do |t|
t.string :commenter t.string :commenter
t.text :body t.text :body
# this line adds an integer column called `article_id`.
t.references :article, index: true, foreign_key: true t.references :article, index: true, foreign_key: true
t.timestamps null: false t.timestamps null: false
...@@ -1556,9 +1554,9 @@ class CreateComments < ActiveRecord::Migration ...@@ -1556,9 +1554,9 @@ class CreateComments < ActiveRecord::Migration
end end
``` ```
The `t.references` line sets up a foreign key column for the association between The `t.references` line creates an integer column called `article_id`, an index
the two models. An index for this association is also created on this column. for it, and a foreign key constraint that points to the `articles` table. Go
Go ahead and run the migration: ahead and run the migration:
```bash ```bash
$ bin/rake db:migrate $ bin/rake db:migrate
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册