Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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.

share|improve this question
    
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. – hightempo Jun 20 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) – Криси Стоянов Jun 20 at 17:06
up vote 1 down vote accepted

Use integer type instead of references

add_column :questions, :quiz_id, :integer
share|improve this answer
    
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. – Криси Стоянов Jun 20 at 17:10
    
@КрисиСтоянов I fixed my answer – itsnikolay Jun 20 at 17:13
    
thanks that did the trick :) – Криси Стоянов Jun 20 at 17:33
    
@КрисиСтоянов you can mark my answer as correct one also ;) – itsnikolay Jun 20 at 19:53
1  
oh sorry, I forgot, thanks for reminding me :) – Криси Стоянов Jun 20 at 20:19

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.