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