My issue: migrated from SQLITE3 today to POSTRESQL 9.4 on my Rails app. I've looked in StackOverflow, and also followed the instructions here: http://sevenseacat.net/2015/02/24/add_foreign_key_gotchas.html
Can't seem to figure this out. Error is:
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: relation "birds" does not exist
: ALTER TABLE "appointments" ADD CONSTRAINT "fk_rails_5464f9f71b"
FOREIGN KEY ("bird_id")
REFERENCES "birds" ("id")
I've also gotten the above error in relation to my appointments table - pretty much the same deal.
If I remove foreign keys from all tables, migration works perfectly!
Here's my birds migration:
class CreateBirds < ActiveRecord::Migration
def change
enable_extension "plpgsql"
create_table :birds do |t|
t.references :customer, index: true
t.string :name
t.string :breed
t.string :color
t.string :age
t.string :notes
t.timestamps null: false
end
add_foreign_key :birds, :customers, column: :customer_id
end
end
and the model:
class Bird < ActiveRecord::Base
belongs_to :customer
has_many :appointments
def self.search(search)
where("name LIKE ?", "%#{search}%")
end
end
I've adjusted and readjusted these files based on advice I've gotten from other sources and can't seem to figure this out.