Home>

I am trying to create a chat site with rails, but to create a fixed chat room
I decided to create it by writing the initial data first with seed.
It worked well in my local environment.
However, deploying with heroku and using the command of heroku run rails db:seed
When I type in and try to fly to each place, it says that the page does not exist.

(Since it is made in seed.rb in order, the route corresponding to that id is selected with and skipped.)

Applicable source code
User.create!(
  nickname: "staff",
  team_id: 11,
  favorite_player: "Taneichi",
  introduction: "test",
  email:'[email protected]',
  password:'aaa111'
)
Room.create!(
  name: "Yomiuri Giants exclusive chat",
  content: "test",
  user_id: "1",
  official: "Yes"
)
Room.create!(
  name: "Yokohama DeNA Baystars exclusive chat",
  content: "test",
  user_id: 1,
  official: "Yes"
)
Room.create!(
  name: "Chat for Hanshin Tigers",
  content: "test",
  user_id: 1,
  official: "Yes"
)
Room.create!(
  name: "Yakult Swallows exclusive chat",
  content: "test",
  user_id: 1,
  official: "Yes"
)
Room.create!(
  name: "Chunichi Lions exclusive chat",
  content: "test",user_id: 1,
  official: "Yes"
)
Room.create!(
  name: "Chat for Hiroshima Carp",
  content: "test",
  user_id: 1,
  official: "Yes"
)
Room.create!(
  name: "Softbank Hawks exclusive chat",
  content: "test",
  user_id: "1",
  official: "Yes"
)
Room.create!(
  name: "Chat for Seibu Lions",
  content: "test",
  user_id: 1,
  official: "Yes"
)
Room.create!(
  name: "Chat for Chiba Lotte Marines",
  content: "test",
  user_id: 1,
  official: "Yes"
)
Room.create!(
  name: "Rakuten Eagles exclusive chat",
  content: "test",
  user_id: 1,
  official: "Yes"
)
Room.create!(
  name: "Oryx Buffaloes exclusive chat",
  content: "test",
  user_id: 1,
  official: "Yes"
)
Room.create!(
  name: "Nippon Ham Fighters exclusive chat",
  content: "test",
  user_id: 1,official: "Yes"
)
Welcome!<ul><%=image_tag "s-team.png", class: "spteam"%><li><%=image_tag "giants_icon.png", class:"icon"%>Yomiuri Giants</li><li><%=image_tag "baystars_icon.png", class:"icon"%>Yokohama DeNA Baystars</li><li><%=image_tag "tigers_icon.png", class:"icon"%>Hanshin Tigers</li><li><%=image_tag "swallows_icon.png", class:"icon"%>Yakult Swallows</li><li><%=image_tag "dragons_icon.png", class:"icon"%>Chunichi Lions</li><li><%=image_tag "carp_icon.png", class:"icon"%>Hiroshima Carp</li></ul><ul><%=image_tag "p-team.png", class: "spteam"%><li><%=image_tag "hawks_icon.png", class:"icon"%>SoftBank Hawks</li><li><%=image_tag "lions_icon.png", class:"icon"%>Seibu Lions</li><li><%=image_tag "marines_icon.png", class:"icon"%>Chiba Lotte Marines</li><li><%=image_tag "eagles_icon.png", class:"icon"%>Rakuten Eagles</li><li><%=image_tag "buffaloes_icon.png", class:"icon"%>Oryx Buffaloes</li><li><%=image_tag "fiters_icon.png", class:"icon"%>Nippon Ham Fighters</li></ul>
log
Running rake db:seed on ⬢ baseball-chat2020... up, run.2551 (Free)
DEPRECATION WARNING: Including LoggerSilence is deprecated and will be removed in Rails 6.1. Please use `ActiveSupport::LoggerSilence` instead (called from<top (required)>at /app/config/application.rb:7)
   (2.1ms) SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode,',STRICT_ALL_TABLES'),',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
   (2.2ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
   (2.0ms) SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode,',STRICT_ALL_TABLES'),',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
   (2.9ms) BEGIN
  User Exists? (2.9ms) SELECT 1 AS one FROM `users` WHERE `users`.`email` = BINARY'[email protected]' LIMIT 1
  User Create (3.0ms) INSERT INTO `users` (`nickname`, `team_id`, `favorite_player`, `introduction`, `email`, `encrypted_password`, `created_at`, `updated_at`) VALUES ('staff', 11,'Taneichi','test','[email protected]','$2a$12$1XSOSKPFJKSnfL25leecQu1w2eDuo07i7itshhkBqyEd.YROCJiY2', '2020-09-04 04:48:39', '2020-09-04 04: 48:39')
   (8.4ms) COMMIT
   (2.0ms) BEGIN
  User Load (2.1ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Room Create (2.0ms) INSERT INTO `rooms` (`name`, `content`, `user_id`, `official`, `created_at`, `updated_at`) VALUES ('Yomiuri Giants chat','test', 1 ,'Yes', '2020-09-04 04:48:39', '2020-09-04 04:48:39')
   (9.2ms) COMMIT
   (1.9ms) BEGIN
  User Load (1.9ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Room Create (2.0ms) INSERT INTO `rooms` (`name`, `content`, `user_id`, `official`, `created_at`, `updated_at`) VALUES ('Yokohama DeNA Baystars Chat','test', 1,'Yes', '2020-09-04 04:48:39', '2020-09-04 04:48:39')
   (8.2ms) COMMIT(2.0ms) BEGIN
  User Load (2.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Room Create (2.1ms) INSERT INTO `rooms` (`name`, `content`, `user_id`, `official`, `created_at`, `updated_at`) VALUES ('Hanshin Tigers Chat','test', 1 ,'Yes', '2020-09-04 04:48:39', '2020-09-04 04:48:39')
   (10.6ms) COMMIT
   (1.9ms) BEGIN
  User Load (1.9ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Room Create (1.9ms) INSERT INTO `rooms` (`name`, `content`, `user_id`, `official`, `created_at`, `updated_at`) VALUES ('Yakult Swallows exclusive chat','test', 1 ,'Yes', '2020-09-04 04:48:39', '2020-09-04 04:48:39')
   (9.2ms) COMMIT
   (1.8ms) BEGIN
  User Load (1.8ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Room Create (1.8ms) INSERT INTO `rooms` (`name`, `content`, `user_id`, `official`, `created_at`, `updated_at`) VALUES ('Chunichi Lions chat','test', 1,'Yes', '2020-09-04 04:48:39', '2020-09-04 04:48:39')
   (9.7ms) COMMIT
   (2.0ms) BEGIN
  User Load (2.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Room Create (1.9ms) INSERT INTO `rooms` (`name`, `content`, `user_id`, `official`, `created_at`, `updated_at`) VALUES ('Hiroshima Carp chat','test', 1 ,'Yes', '2020-09-04 04:48:39', '2020-09-04 04:48:39')
   (11.6ms) COMMIT
   (1.9ms) BEGIN
  User Load (2.1ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Room Create (3.1ms) INSERT INTO `rooms` (`name`, `content`, `user_id`, `official`, `created_at`, `updated_at`) VALUES ('SoftBank Hawks chat','test', 1 ,'Yes', '2020-09-04 04:48:39', '2020-09-04 04:48:39')
   (11.9ms) COMMIT
   (2.0ms) BEGIN
  User Load (1.9ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Room Create (1.8ms) INSERT INTO `rooms` (`name`, `content`, `user_id`, `official`, `created_at`, `updated_at`) VALUES ('Seibu Lions Chat','test', 1 ,'Yes', '2020-09-04 04:48:39', '2020-09-04 04:48:39')
   (8.9ms) COMMIT
   (1.9ms) BEGIN
  User Load (2.6ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Room Create (2.0ms) INSERT INTO `rooms` (`name`, `content`, `user_id`, `official`, `created_at`, `updated_at`) VALUES ('Chiba Lotte Marines chat','test', 1,'Yes', '2020-09-04 04:48:39', '2020-09-04 04:48:39')
   (8.7ms) COMMIT
   (1.9ms) BEGIN
  User Load (1.8ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Room Create (1.9ms) INSERT INTO `rooms` (`name`, `content`, `user_id`, `official`, `created_at`, `updated_at`) VALUES ('Rakuten Eagles chat','test', 1 ,'Yes', '2020-09-04 04:48:39', '2020-09-04 04:48:39')
   (8.9ms) COMMIT
   (2.3ms) BEGIN
  User Load (2.6ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Room Create (2.0ms) INSERT INTO `rooms` (`name`, `content`, `user_id`, `official`, `created_at`, `updated_at`) VALUES ('Orix Buffaloes chat','test', 1 ,'Yes', '2020-09-04 04:48:39', '2020-09-04 04:48:39')
   (9.9ms) COMMIT
   (2.2ms) BEGIN
  User Load (1.8ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Room Create (2.0ms) INSERT INTO `rooms` (`name`, `content`, `user_id`, `official`, `created_at`, `updated_at`) VALUES ('Nippon Ham Fighters Chat','test', 1,'Yes', '2020-09-04 04:48:39', '2020-09-04 04:48:39')
   (11.3ms) COMMIT
Supplemental information (FW/tool ​​version, etc.)

rails 6.0.0

  • Answer # 1

    For some reason when I try the heroku pg:psql command, it says baseball-chat2020 has no databases and the database is not displayed.

    If so, I think it is better to create a database first and then execute seed.

    heroku run rails db:migrate
    heroku run rails db:seed

    Also, due to the nature of the application, it is safer to specify the seed data ID.

    Room.create!(
      id: 1,
      name: "Yomiuri Giants exclusive chat",
      content: "test",
      user_id: "1",
      official: "Yes"
    )