Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm getting a weird error. I had sqlite3 working and now switching over to postgres, i'm getting this error.

I have migrations, and I had to add a new column.

create_ideas migration

class CreateIdeas < ActiveRecord::Migration
  def change
    create_table :ideas do |t|
      t.string :name
      t.text :description
      t.string :picture

      t.timestamps
    end
    add_foreign_key :ideas, :lists
  end
end

add_list_id_column_to_ideas migration

class AddListIdColumnToIdeas < ActiveRecord::Migration
  def change
    add_column :ideas, :list_id, :integer

  end
end

What is wrong with my foreign key? I get the error when I do rake db:migrate

I have another migration with foreign key, and no errors yet? Maybe its catching the first error first before seeing the other one, but I have this one too:

create_comments migration

class CreateComments < ActiveRecord::Migration
  def change
    create_table :comments do |t|
      t.string :user_name
      t.text :body
      t.integer :idea_id

      t.timestamps
    end
    add_foreign_key :comments, :ideas
  end
end

last migration I have create_lists

class CreateLists < ActiveRecord::Migration
  def change
    create_table :lists do |t|
      t.string :name
      t.text :description
      t.string :picture

      t.timestamps
    end
  end
end

Any clue why I'm getting errors?

Thanks

edit

my relationships

comments model

belongs_to :idea

idea model

belongs_to :list
has_many :comments

list model

has_many :ideas
share|improve this question
 
The CreateLists migration has already been run before the CreateIdeas correct? –  Deekor Apr 29 at 0:33
 
I think CreateIdeas is first to run. Also, to give a sense of my relations: in my comments model I have belongs_to :ideas and then in my idea model I have belongs_to :list and has_many :comments and then in my list model I have has_many :ideas –  andrewliu Apr 29 at 0:35
 
Just a guess but shouldn't CreateLists be run first to create the list table before trying to make the list table a foreign key? –  Deekor Apr 29 at 0:37
 
@Deekor hmmm I'm not sure? I'm new to ruby on rails. How would I create this? The migration file name is ordered where create_ideas is first? –  andrewliu Apr 29 at 3:29
 
@Deekor I did a little digging, and I did rake db:migrate:up VERSION = 2013... the version number of create_list file and then I tried rake db:migrate but it still gives errors. I also tried to do the version of just the create_idea also, but still doesn't work. –  andrewliu Apr 29 at 3:42
show 1 more comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.