在 rails 中添加索引

adding index in rails

我在 运行 rake db:migrate 之后添加了 has_many 和 belongs_to。我添加了这些关联并再次抽取 db:migrate。没有生成索引。你能告诉我这是为什么吗?

以下是我的联想

class 开发人员 < ActiveRecord::Base has_many:评价 has_many :final_scores belongs_to:主管 结束

class评价

class FinalScore < ActiveRecord::Base belongs_to:开发者 结束

class 主管 < ActiveRecord::Base has_many:开发人员 has_many :evaluations :through => :developers 结束

查看有关此主题的官方 rails 指南:http://edgeguides.rubyonrails.org/association_basics.html#the-has-many-association

这里可以看到需要更改生成的迁移文件,自己添加字段。

这个blog有助于更好地理解。您可能遗漏了迁移文件中的某些内容。