Rails 4 - rake db:seed上的nil值

时间:2014-05-20 17:22:02

标签: ruby-on-rails ruby ruby-on-rails-4

我正在使用Rails 4,并创建了一个seed.rb文件,其中包含要添加到我的数据库的值。

这是db模式(Postgres DB):

create_table :teams do |t|
  t.string :name
  t.string :nickname
  t.string :icon
  t.text :description
  t.timestamps
end

这是种子行:

Team.create(id: 367, name: 'Wright State Raiders', icon: 'logos/Wright-State-Raiders.gif')

注意:我正在使用carrierwave来处理图标,但我想我也可以直接加载它们?

以下是development.log

中的行
INSERT INTO "teams" ("created_at", "icon", "id", "name", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"[0m  [["created_at", Tue, 20 May 2014 17:13:23 UTC +00:00], ["icon", nil], ["id", 367], ["name", "Wright State Raiders"], ["updated_at", Tue, 20 May 2014 17:13:23 UTC +00:00]]

知道为什么icon值为nil?这发生在所有350多行上。

编辑:添加可能是问题的一部分的更多信息。

Team型号:

class Team < ActiveRecord::Base
  has_and_belongs_to_many :games
  mount_uploader :icon, IconUploader
end

Game型号:

class Game < ActiveRecord::Base
  has_and_belongs_to_many :teams
  mount_uploader :icon, IconUploader
end

涉及的其他表格:

create_table :teams_mid, id: false do |t|
  t.belongs_to :team
  t.belongs_to :game
end

create_table :games do |t|
  t.string :title
  t.text :description
  t.string :icon
  t.timestamps
end

来自rails c

bundle :004 > Team.create(id: 400, name: 'Wright State Raidersll', icon: 'logos/Wright-State-Raiders.gif')
 (0.2ms)  BEGIN SQL (0.6ms)  INSERT INTO "teams" ("created_at", "icon", "id", "name", "updated_at")     VALUES ($1, $2, $3, $4, $5) RETURNING "id"  [["created_at", Tue, 20 May 2014 19:07:30 UTC +00:00], ["icon", nil], ["id", 400], ["name", "Wright State Raidersll"], ["updated_at", Tue, 20 May 2014 19:07:30 UTC +00:00]]
 (2.1ms)  COMMIT => #<Team id: 400, name: "Wright State Raidersll", nickname: nil, icon: nil, description: nil, created_at: "2014-05-20 19:07:30", updated_at: "2014-05-20 19:07:30">

0 个答案:

没有答案