1

Hello I started my rails application using sqlite, however when I tried deploying it on heroku I found out that I needed to use postgreSQL. So I went through the trouble to change my gemfile and database.yml file and create the new postgresql database. However when I try to migrate my database I get the error:

ActiveRecord::StatementInvalid: PG::UndefinedObject: ERROR:  type "reference" does not exist

LINE 1: ALTER TABLE "questions" ADD "quiz_id" reference

that is probably because I used a reference to make a relation in my db

I am basically looking for the fix for this situation.

Here are my migrations(if it matters):

class CreateQuestions < ActiveRecord::Migration
def change
  create_table :questions do |t|
    t.string :question
    t.string :answer1
    t.string :answer2
    t.string :answer3
    t.string :answer4
    t.integer :correct_id

    t.timestamps null: false
  end
end
end

class CreateQuizzes < ActiveRecord::Migration
def change
  create_table :quizzes do |t|
    t.string :name
    t.string :subject

    t.timestamps null: false
  end
end

end

class AddQuizIdToQuestions < ActiveRecord::Migration
  def change
    add_column :questions, :quiz_id, :reference
  end
end

Edit new question: When on my heroku server there are some dead pages, but not when I am running on my local server. Here is my heroku address: https://krisquiz.herokuapp.com/

The dead pages are when you submit a question and when you try and start a quiz. I looked at the urls and they look properly. The only thing in common that I can think of for the two pages is that I built the urls manually for the links (ex: request.base_url + '/quiz/' + quiz.id.to_s + '/start'). As I am not sure what I need to give you as information just tell me and I will try to quickly get back to you.

2
  • What does your migration look like? It sounds to me like there's something wrong with your migration, like you are trying to modify an column of a table that does not exist. Commented Jun 20, 2016 at 17:01
  • Well I haven't created any new migrations since I changed(or atleast tried changing the database) all of the migrations worked back when I was on sqlite so I guessed that the problem is in postgresql. Either way here are my migrations ( I will edit them into my question) Commented Jun 20, 2016 at 17:06

1 Answer 1

1

Use integer type instead of references

add_column :questions, :quiz_id, :integer
Sign up to request clarification or add additional context in comments.

3 Comments

sorry, I don't think I understand. Isn't reference a type(like integer, string..). Plus I can't seem to find the file you have mentioned.
@КрисиСтоянов I fixed my answer
@КрисиСтоянов you can mark my answer as correct one also ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.