【问题标题】:rake db:seed creates rows, but not the datarake db:seed 创建行,但不创建数据
【发布时间】:2011-03-22 00:23:21
【问题描述】:

因此,当我使用一些 ruby​​ 运行 rake db:seed 以在表中创建 23 行时,它会创建 23 行但不使用我引入的数据。代码如下所示 -

control_words = ControlWord.create([
 {:text => 'herp', :status => 'positive'},
 {:text => 'foo', :status => 'positive'}
])

这可能有点愚蠢,但我尝试过创建一个数组并循环遍历每个数组,但它给了我相同的结果。我在这里做错了什么?

【问题讨论】:

    标签: ruby-on-rails database ruby-on-rails-3


    【解决方案1】:

    试试这个:

    textstatus 字段设为非空。然后使用ControlWord.create!(和!)看看是否有错误。

    我感觉您的模型中可能缺少attr_accessible :text, :status,并且这些字段可能为空,因此没有数据也没有错误。

    【讨论】:

    • 不。那也没有解决问题。
    猜你喜欢
    • 2013-12-30
    • 2012-04-16
    • 2016-07-14
    • 2017-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    • 2019-12-24
    相关资源
    最近更新 更多