2016-05-30 3 views
0

У меня возникла проблема с переносом моей базы данных на Heroku. Я проверил другие проблемы, которые устраняют это безрезультатно. Я действительно могу использовать вторую пару глаз для моего кода, чтобы помочь мне понять это.RoR: Невозможно перенести базу данных в Heroku

Это ошибка, я получаю:

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

PG::UndefinedTable: ERROR: relation "props" does not exist 
: ALTER TABLE "comments" ADD CONSTRAINT "fk_rails_1d3f70cf04" 
FOREIGN KEY ("prop_id") 
    REFERENCES "props" ("id") 

enter image description here

кажется, пойманы во время миграции этот файл:

class CreateComments < ActiveRecord::Migration 
    def change 
    create_table :comments do |t| 
     t.string :commenter 
     t.text :body 
     t.references :prop, index: true, foreign_key: true 

     t.timestamps null: false 
    end 
    end 
end 

Это файл миграции, где я создаю таблицу реквизиты:

class CreateProps < ActiveRecord::Migration 
    def change 
    create_table :props do |t| 
     t.string :title 
     t.text :text 
     t.references :user, index: true, foreign_key: true 

     t.timestamps null: false 
    end 
    end 
end 

Моя схема здесь:

ActiveRecord::Schema.define(version: 20160528205746) do 

    # These are extensions that must be enabled in order to support this database 
    enable_extension "plpgsql" 

    create_table "answers", force: :cascade do |t| 
    t.string "choice" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
    t.string "created_by" 
    t.integer "user_id" 
    t.integer "prop_id" 
    end 

    create_table "comments", force: :cascade do |t| 
    t.string "commenter" 
    t.text  "body" 
    t.integer "prop_id" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
    end 

    add_index "comments", ["prop_id"], name: "index_comments_on_prop_id", using: :btree 

    create_table "props", force: :cascade do |t| 
    t.string "title" 
    t.text  "text" 
    t.integer "user_id" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
    t.string "choice" 
    t.string "answer" 
    t.integer "answerId" 
    end 

    add_index "props", ["user_id"], name: "index_props_on_user_id", using: :btree 

    create_table "user_answers", force: :cascade do |t| 
    t.integer "user_id" 
    t.integer "answer_id" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    end 

    create_table "users", force: :cascade do |t| 
    t.string "username" 
    t.string "email" 
    t.integer "score",   default: 0 
    t.integer "prop_id" 
    t.datetime "created_at",      null: false 
    t.datetime "updated_at",      null: false 
    t.string "password_digest" 
    t.string "created_by" 
    t.boolean "admin",   default: false 
    t.integer "answers_id" 
    t.integer "answer_id" 
    end 

    add_index "users", ["answer_id"], name: "index_users_on_answer_id", using: :btree 
    add_index "users", ["prop_id"], name: "index_users_on_prop_id", using: :btree 

    create_table "wins", force: :cascade do |t| 
    t.string "correctAnswer" 
    t.integer "user_id" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
    end 

    add_index "wins", ["user_id"], name: "index_wins_on_user_id", using: :btree 

    add_foreign_key "users", "answers" 
end 
+0

Помимо того, что bkunzi01 сказал, попытайтесь решить эту проблему с помощью migrat ион. Потому что, как только вы делаете db: drop, все данные будут потеряны. Поэтому, если что-то подобное происходит снова в производстве, вы не можете позволить себе потерять данные. – gates

ответ

1

Проблема заключается в том, вы создаете ссылку на таблицу, которая еще не создана. Удалите ссылку из этой миграции в реквизиты, затем добавьте таблицу реквизитов и добавьте миграцию, реализующую связь. Если вы не нужны данные в настоящее время в БД я хотел бы сделать «грабли БД: падение» и редактировать файлы миграции

Update (только если вы Арент сотрудничество с другими!):

ли рельсы add_ref_to_comments г миграции

Затем измените миграцию иметь:

защиту изменить add_reference: реквизит,: комментарий, индекс: истинный конца

+0

Спасибо! Можете ли вы показать/рассказать мне, как будет выглядеть новая миграция для переопределения ассоциации? Я точно не знаю, как воссоздать ассоциацию. – CodeYogi

+0

Уверенный один секунда на моем телефоне lol – bkunzi01

+0

Спасибо ... Я попытался удалить несколько строк из кода, включая ассоциацию из моей схемы и из файла миграции, и он все еще не работает? – CodeYogi

Смежные вопросы