2017-03-09 71 views
0

我的应用程序完美的作品在发展,但是当我尝试为它服务在Heroku上,我得到以下错误:不能运行的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

这是我的DB模式:

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 

这是我的ENV:

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) 

该项目与轨道4以后创建并更新到轨5

哪能迁移我的数据库在Heroku?

感谢您的阅读。

+1

你试过跑'Heroku的耙分贝:模式:load'直接加载在Heroku您的架构? – Iceman

+1

heroku rake db:schema:load,Worked correctly;任何可能发生的事情的想法? @Iceman –

+0

Goo,d我给出了解释的答案。 – Iceman

回答

3

这样做的推荐的方法是运行

heroku rake db:schema:load 

,因为它从你的开发数据库对生产服务器加载工作模式。使用迁移不推荐,这是从官方指南

Migrations, mighty as they may be, are not the authoritative source for your database schema. That role falls to either db/schema.rb or an SQL file which Active Record generates by examining the database. They are not designed to be edited, they just represent the current state of the database.

http://edgeguides.rubyonrails.org/active_record_migrations.html#schema-dumping-and-you

+1

感谢您的帮助! –

+0

其实,我想你想'heroku运行rake db:schema:load'。我相信'heroku rake'语法已被弃用。 – moveson

相关问题