【发布时间】:2017-07-30 12:39:18
【问题描述】:
我的应用程序在开发中运行良好,但是当我尝试在 Heroku 上提供它时,我收到以下错误:
PG::UndefinedTable: ERROR: relation "users" does not exist
: CREATE TABLE "games" ("id" serial primary key, "title" character varying, "image" character varying, "description" character varying, "user_id" integer, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_de9e6ea7f7"
FOREIGN KEY ("user_id")
REFERENCES "users" ("id")
)
当我尝试运行 heroku rake db:drop, heroku rake db:reset, heroku rake db:migrate 时出现该错误。
这是我的数据库架构:
ActiveRecord::Schema.define(version: 20170305021159) do
create_table "comments", force: :cascade do |t|
t.string "body"
t.integer "user_id"
t.integer "game_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["game_id"], name: "index_comments_on_game_id"
t.index ["user_id"], name: "index_comments_on_user_id"
end
create_table "games", force: :cascade do |t|
t.string "title"
t.string "image"
t.string "description"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
t.index ["user_id"], name: "index_games_on_user_id"
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
end
这是我的环境:
Rails version 5.0.2
Ruby version 2.3.1-p112 (x86_64-linux-gnu)
RubyGems version 2.5.1
Rack version 2.0.1
JavaScript Runtime Node.js (V8)
这个项目是用 rails 4 创建的,后来更新到 rails 5。
如何在 Heroku 中迁移我的数据库?
感谢阅读。
【问题讨论】:
-
您是否尝试过运行
heroku rake db:schema:load直接在heroku 上加载您的架构? -
heroku rake db:schema:load,工作正常;知道会发生什么吗? @冰人
-
很好,我做了一个解释的答案。
标签: ruby-on-rails ruby postgresql heroku ruby-on-rails-5