第一个也是唯一一个用户在Heroku

时间:2015-12-20 15:15:10

标签: ruby-on-rails database-migration

部署我的应用程序后,我创建了一个新用户,并注意到地址栏在网址末尾报告了第2位:htt://...herokuapp.com/users/2。

所以我首先在生产环境中使用rails控制台检查,然后在Heroku处检查。在我的生产环境中似乎没有任何不规则(运行sqlite3),所以我运行heroku run console --sandbox并得到以下结果:

irb(main):001:0> User.count
   (4.9ms)  SELECT COUNT(*) FROM "users"
   (4.9ms)  SELECT COUNT(*) FROM "users"
=> 1


irb(main):002:0> User.first
  User Load (2.5ms)  SELECT  "users".* FROM "users"  ORDER BY "users"."id" ASC LIMIT 1
  User Load (2.5ms)  SELECT  "users".* FROM "users"  ORDER BY "users"."id" ASC LIMIT 1
=> #<User id: 2, name: "Mark Homburg", email: "mark.homburg@yahoo.com", created_at: "2015-12-20 13:56:04", updated_at: "2015-12-20 13:56:04", password_digest: "...">


irb(main):001:0> User.find(1)
  User Load (1.1ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1  [["id", 1]]
  User Load (1.1ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1  [["id", 1]]
ActiveRecord::RecordNotFound: Couldn't find User with 'id'=1

Heroku的不正之处是运行User.countUser.firstUser.find(1)后重复的SELECT FROM“users”操作。正如我所说,我的生产环境中的相应命令没有任何不规则之处:

>> User.find(1)
  User Load (0.4ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", 1]]
=> #<User id: 1, name: "Rails Tutorial", email: "example@railstutorial.org", created_at: "2015-12-20 10:08:22", updated_at: "2015-12-20 10:08:22", password_digest: "...">

在我看来,这可以通过数据库中存在重复的用户表来解释,正如我在Duplicate migrations in topic branch中尝试解释的那样。 你有什么看法,你建议我做什么?

0 个答案:

没有答案