0
我使用find_by_id檢索Post實例,在其上設置分數並調用保存。我看到的是一個非常奇怪的錯誤,其中SQL缺少WHERE子句中的字段。這裏是我的鐵軌控制檯輸出:模型保存方法導致異常「沒有這樣的列」列名爲空
me> rails c
Loading development environment (Rails 3.2.22.2)
2.1.5 :001 > post = Post.find_by_id 123456
Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123456 LIMIT 1
=> #<Post id: 123456, url: "http://www.example.com", title: "Test Title", score: nil>
2.1.5 :002 > post.score = 1
=> 1
2.1.5 :003 > post.save
(0.1ms) begin transaction
(0.2ms) UPDATE "posts" SET "score" = 1 WHERE "posts"."" = 123456
(0.0ms) rollback transaction
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: posts.: UPDATE "posts" SET "score" = 1 WHERE "posts"."" = 123456
缺少ID的字段。你在這裏做什麼奇怪的事情?像在遷移中爲字段設置數據庫選項一樣?你可以粘貼你的帖子遷移? – trh
@trh是的,我有':id => false'在create_table for:posts – slowpoison