我有一个具有多个属性( 、 等...)的 Products 模型,customer_type
我customer_name
正在dept_type
尝试用一些数据为其播种。
我的db/seeds.rb
文件中有以下内容
Product.create(customer_type:'Retailer', customer_name: 'Walmart', dept_type: 'Grocery')
我保存文件然后运行rake db:Seed
我没有收到错误消息但是当我加载我的应用程序时没有任何数据存在?我在这里做错了什么?
我也尝试过rake db:setup
,rake db:reset
每次它都没有返回错误消息,但没有加载数据。
更新我修改了我的数据库种子文件看起来像这样
Product.create!(customer_type:'Retailer', customer_name: 'Walmart', dept_type: 'Grocery')
当我运行 rake db:reset 时出现错误“验证失败:客户类型未包含在列表中”
带有验证的我的产品模型文件
class Product < ActiveRecord::Base
attr_accessible :customer_type
has_many :line_items
has_many :orders, through: :line_items
CUSTOMER_TYPES = ["Retailer", "Manufacturer"]
validates :customer_type, inclusion: CUSTOMER_TYPES
我已经尝试使用客户类型值零售商和制造商来播种数据库,但运气不好