【问题标题】:rake db:fixtures:load on factory_girlrake db:fixtures:load on factory_girl
【发布时间】:2011-09-01 06:20:10
【问题描述】:

我使用“rake db:fixtures:load”将虚拟数据插入到开发数据库中。我开始使用 factory_girl。有没有办法将 RAILS_ROOT/spec/factories/*.rb 中的数据插入到开发数据库中?

【问题讨论】:

    标签: ruby-on-rails factory-bot fixtures


    【解决方案1】:

    工厂并非旨在填充数据库。它们将为您的对象属性生成随机数据(除非另有说明)。因此,它不会用定义的数据填充开发数据库。

    你应该在这里使用的是种子。更多信息:

    http://ryandaigle.com/articles/2009/5/13/what-s-new-in-edge-rails-database-seedinghttp://rails-bestpractices.com/posts/20-isolating-seed-data

    【讨论】:

    • 谢谢你,jbescoyez。我通常使用种子来插入主数据,如所有环境的国家名称、州或类别。
    猜你喜欢
    • 2014-11-07
    • 2012-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多