Ruby on rails PG::Rails重命名列后未定义列

Ruby on rails PG::Rails重命名列后未定义列,ruby-on-rails,postgresql,Ruby On Rails,Postgresql,在rails中运行名称更改后,我出现了上述错误 PG::UndefinedColumn at /books/17 ERROR: column "books_count" does not exist at character 45 STATEMENT: UPDATE "users" SET "books_count" = COALESCE("books_count", 0) - 1 WHERE "users"."id" = $1 我第一次注意到这个问题是在试图删除一本书时。否则,一切正常。

在rails中运行名称更改后,我出现了上述错误

PG::UndefinedColumn at /books/17
ERROR:  column "books_count" does not exist at character 45
STATEMENT:  UPDATE "users" SET "books_count" = COALESCE("books_count", 0) - 1 WHERE "users"."id" = $1
我第一次注意到这个问题是在试图删除一本书时。否则,一切正常。Postgresql中是否也有我必须更改的列?或者我应该恢复名称更改吗

我已经重新启动了服务器

编辑:当前模式

def change
    rename_column :users, :books_count, :books_shared
  end
分享的书算是书。没有其他书籍的实例

联想

create_table "users", force: :cascade do |t|
    t.string   "email",                  default: "", null: false
    t.string   "encrypted_password",     default: "", null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",          default: 0,  null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.inet     "current_sign_in_ip"
    t.inet     "last_sign_in_ip"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "name"
    t.integer  "books_shared",           default: 0
    t.integer  "books_read",             default: 0
  end
classbook
默认情况下,Rails会查找多重关联模型,后跟
\u count
,在您的示例中,它是
books\u count

在此处查看
所属的文档,并查找
计数器缓存

您可以为Book类上的计数器缓存指定自定义列名,如下所示:


属于:用户,计数器\u缓存::图书\u共享

数据库中是否存在:图书\u计数列?你也可以复制粘贴你的模型中的表关联。迁移后,我搜索了整个应用程序。没有图书计数的迹象。你把桌子的名字从图书计数改为图书共享也许这就是原因。另外,您还没有发布模型中存在的关联。我想我发现了问题,这是因为我的计数器缓存绑定到了books\u count。
class Book < ActiveRecord::Base
      belongs_to :user, counter_cache: true
      validates :title, presence: true, length: {minimum: 3}
      validates :author, presence: true
      has_many :book_checkouts
    end