In Rails 5 - when we refer to a model, an index is automatically created in foreign_key.
Migration API changed in Rails 5 -
Rails 5 API , - , null: false , null .
, , . , Rails 5 , index: true. , .
- ( http://blog.bigbinary.com/2016/03/01/migrations-are-versioned-in-rails-5.html)
rails g model Task user:references
Rails 4
class CreateTasks < ActiveRecord::Migration
def change
create_table :tasks do |t|
t.references :user, index: true, foreign_key: true
t.timestamps null: false
end
end
end
5
class CreateTasks < ActiveRecord::Migration[5.0]
def change
create_table :tasks do |t|
t.references :user, foreign_key: true
t.timestamps
end
end
end