ruby-on-rails - 运行 rake db :setup removes all my users data

标签 ruby-on-rails ruby database rake scaffold

在我的 Ruby on Rails 应用程序中,我有种子文件,其中包含有关用户的数据,例如:

User.create(:password => "jb", :password_confirmation => "jb", :role => 'admin', :first_name => "Joe", :last_name => "Bloggs",  :house_no => "1", :street => "A Street", :town => "A Town", :postcode => "ABC1 2DE", :email => "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f998979c94989095b998979c94989095989d9d8b9c8a8ad79a96d78c92" rel="noreferrer noopener nofollow">[email protected]</a>")

但是当我运行rake db:setup时,它会删除我通过应用程序输入数据库的所有用户数据(这很好并且符合预期),但不会从应用程序输入用户数据种子。

我不确定这是否会产生影响,但我最近连续做了三个脚手架。

我做错了什么?

最佳答案

我认为您正在寻找rake db:seed。这是其他 db rake 任务的很好解释 Difference between rake db:migrate db:reset and db:schema:load

关于ruby-on-rails - 运行 rake db :setup removes all my users data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28589482/

相关文章:

ruby-on-rails - rails : How to test state_machine?

ruby - 在 Nokogiri 完成抓取之前,Watir-webdriver 正在通过脚本进行处理

ruby - Rspec 和 bundle exec

asp.net - 将文件存储为数据库中的字节数组,安全风险?

ruby-on-rails - 即使安装了 libv8,Gem therubyracer 也不会安装

sql - ActiveRecord has_many 通过多态 has_many

ruby-on-rails - 如何仅在使用 ElasticSearch 和 Tire 存在时按属性过滤搜索?

mysql - 如何处理用户个人资料字段的隐私?

php - MySQL:更新第一个可用列为空的行

mysql - Ruby on Rails : Two Models Both Have Has/Many and Belongs_to