【问题标题】:Add_Index() Error using Rails ,PostGres and Windows xp使用 Rails、PostGres 和 Windows xp 时出现 Add_Index() 错误
【发布时间】:2010-11-15 22:33:45
【问题描述】:

我正在尝试为我的模型添加索引,但不断收到此错误。

PG:错误错误:列“user_id”确实 不存在:创建索引 “index_users_on_user_id”开启“用户” ("user_id")

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.references :role
      t.references :carrier
      t.string "first_name"
      t.string "last_name"
      t.string "user_name"
      t.string "hashed_password"
      t.string "user_salt"
      t.string "telephone"

      t.timestamps
    end
    add_index("users", "user_id")
    add_index("users", "role_id")
    add_index("users", "user_name")
  end

  def self.down
    drop_table :users
  end
end

【问题讨论】:

    标签: ruby-on-rails postgresql ruby-on-rails-3 windows-xp


    【解决方案1】:

    迁移中的任何地方都没有 user_id 列。 rails 为您创建的自动列名为“id”。

    【讨论】:

    • 所以应该是 add_index("users", "id")?
    • 其实这个列是主键,postgresql会为此创建索引,不需要另一个。
    猜你喜欢
    • 2013-12-13
    • 1970-01-01
    • 1970-01-01
    • 2011-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-24
    • 1970-01-01
    相关资源
    最近更新 更多