简体   繁体   中英

PG::UndefinedTable: ERROR when deploying Heroku

After typing heroku run rake db:migrate , I got an error looking like,

rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedTable: ERROR:  relation "notified_bies" does not exist
: CREATE TABLE "notifications" ("id" bigserial primary key, "user_id"     bigint, "notified_by_id" bigint, "post_id" bigint, "identifier" integer,     "notice_type" character varying, "read" boolean, "created_at" timestamp NOT     NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_b080fb4855"
FOREIGN KEY ("user_id")
  REFERENCES "users" ("id")
, CONSTRAINT "fk_rails_ff009aac1a"
FOREIGN KEY ("notified_by_id")
  REFERENCES "notified_bies" ("id")
, CONSTRAINT "fk_rails_ff8a02c41d"
FOREIGN KEY ("post_id")
  REFERENCES "posts" ("id")
)

and, here this is the list of migrate files in db folder.

20180411215502_create_posts.rb
20180411215935_add_attachment_image_to_posts.rb
20180411225346_devise_create_users.rb
20180411230346_add_user_name_to_users.rb
20180411232041_add_user_id_to_posts.rb
20180412001819_create_comments.rb
20180412164718_add_attachment_avatar_to_users.rb
20180412164800_add_bio_to_users.rb
20180412193721_acts_as_votable_migration.rb
20180416212245_create_notifications.rb
20180416235802_create_follow_join_table.rb

20180416212245_create_notifications.rb

CreateNotifications < ActiveRecord::Migration[5.1] 
  def change 
    create_table :notifications do |t| 
      t.references :user, foreign_key: true 
      t.references :notified_by, foreign_key: true 
      t.references :post, foreign_key: true 
      t.integer :identifier 
      t.string :notice_type 
      t.boolean :read 

      t.timestamps 
    end 
  end
end 

I will wait for your suggestions Thank you.

It looks like you are not pointing the reference to the correct table. For an example the notified_by_id should be using the foreign key reference. In that sense the "notified_bies" doesn't exist. If "notified_by_id" is the value from the users table then add it as follows,

t.references :user

The error you are getting occured while creating the foreign key

Updated Answer

This is the reason for the error

t.references :notified_by, foreign_key: true 

Now, I don't believe that you have a model named NotifiedBy which you are trying to reference here.

Maybe you just need an index here on the field. So, you might need to change this to

t.integer :notified_by, index: true 

Old Answer

FOREIGN KEY ("notified_by_id")
  REFERENCES "notified_bies" ("id")
, CONSTRAINT "fk_rails_ff8a02c41d"

You must be creating a reference or a foreign key in 20180416212245_create_notifications.rb .

Removing the entry should fix the issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM