【问题标题】:rails console say "Table doesn't exist" but it shows up in my schemarails 控制台说“表不存在”,但它显示在我的架构中
【发布时间】:2013-01-29 03:30:04
【问题描述】:

我正在为 Equipment 和 Instructors 创建一个名为 EquipmentOwnership 的连接表。

class EquipmentOwnership < ActiveRecord::Base
  attr_accessible :equipment_id, :instructor_id, :owned

  belongs_to :equipment
  belongs_to :instructor
end

它在我的架构中显示如下:

create_table "equiment_ownerships", :force => true do |t|
  t.integer "equipment_id"
  t.integer "instructor_id"
  t.boolean "owned"
end

但是,rails 控制台中会发生以下情况:

[1] pry(main)> EquipmentOwnership
=> EquipmentOwnership(Table doesn't exist)

它这样做的可能原因是什么?

我正在使用 Postgres、rails 3.2、ruby 1.9.3p194 和 OSX 山狮。

【问题讨论】:

  • 您运行迁移了吗? rake db:migrate

标签: ruby-on-rails postgresql rails-activerecord


【解决方案1】:

create_table "equiment_ownerships" 缺少p。所以,应该是:
create_table "equipment_ownerships"

【讨论】:

  • 哇,我不敢相信我没听懂……谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-04
  • 1970-01-01
  • 2021-10-23
  • 2013-07-16
  • 2020-03-13
  • 2022-01-13
相关资源
最近更新 更多