当我尝试
时rake db:reset
或
rake db:drop
rake db:create
rake db:schema:load
rake db:seed
当种子出现时我随机获得NoMethodError: undefined method 'fields' for nil:NilClass
。
这是一个:
[1m[35m (186.0ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('20130318105449')
[1m[36m (187.0ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('20130319154146')[0m
[1m[35m (189.0ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('20130322132730')
[1m[36m (104.0ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('20130322142814')[0m
NoMethodError: undefined method `fields' for nil:NilClass: SELECT COUNT(*)
FROM pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind in ('v','r')
AND c.relname = 'schema_migrations'
AND n.nspname = ANY (current_schemas(false))
这是另一个:
[1m[35m (39.0ms)[0m BEGIN
[1m[36mCategory Exists (107.0ms)[0m [1mSELECT 1 AS one FROM "categories" WHERE "categories"."hash" = 'cat1' LIMIT 1[0m
[1m[35mSQL (124.0ms)[0m INSERT INTO "categories" ("category_id", "created_at", "label", "hash", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["category_id", 58], ["created_at", Mon, 25 Mar 2013 15:07:53 CET +01:00], ["label", "Cat1"], ["hash", "cat1"], ["updated_at", Mon, 25 Mar 2013 15:07:53 CET +01:00]]
[1m[36m (117.0ms)[0m [1mCOMMIT[0m
[1m[35m (162.0ms)[0m BEGIN
[1m[36mCategory Exists (136.0ms)[0m [1mSELECT 1 AS one FROM "categories" WHERE "categories"."hash" = 'cat2' LIMIT 1[0m
[1m[35mSQL (104.0ms)[0m INSERT INTO "categories" ("created_at", "label", "hash", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["created_at", Mon, 25 Mar 2013 15:07:53 CET +01:00], ["label", "Cat2"], ["hash", "cat2"], ["updated_at", Mon, 25 Mar 2013 15:07:53 CET +01:00]]
[1m[36m (99.0ms)[0m [1mCOMMIT[0m
[1m[35m (108.0ms)[0m BEGIN
[1m[36mCategory Exists (173.0ms)[0m [1mSELECT 1 AS one FROM "categories" WHERE "categories"."hash" = 'cat3' LIMIT 1[0m
NoMethodError: undefined method `fields' for nil:NilClass: SELECT 1 AS one FROM "categories" WHERE "categories"."hash" = 'cat3' LIMIT 1
我真的不明白这是从哪里来的。有时我甚至没有错误,一切都完美插入。 经过一些测试后,它似乎取决于插入的速度。如果我从我的开发服务器执行此操作,它几乎总是成功。如果我从我的计算机上执行此操作,它几乎总是失败。
我在我的开发服务器上使用ruby 1.9.3本地和ruby 2。在我使用rails4(边缘)和我的驱动程序是postgresql(pg,没有指定版本)
答案 0 :(得分:12)
我在rails4(边缘)和postgres上也遇到了这个问题。我在solr上遇到它:reindex,所以我认为它不一定与插入有任何关系。当我弄清楚什么是错的时候我会更新这个。
编辑: 尝试更新到rails修订版1a838ccda4a31bb023985f6c977e6bc3e238cda9,它解决了我的问题。
这是github问题:https://github.com/rails/rails/issues/9710
我在快速的git bisect之后发现了它。它现在肯定在git中修复。