迁移heroku时遇到的错误

时间:2016-05-22 08:02:49

标签: ruby-on-rails ruby heroku

我试图在我的heroku发行版上进行迁移。我得到这个错误:

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

PG::UndefinedTable: ERROR:  relation "plants" does not exist
: ALTER TABLE "images" ADD CONSTRAINT "fk_rails_d5e1aedcb5"
FOREIGN KEY ("plant_id")
REFERENCES "plants" ("id")

我的一些桌子经过,但不是这一个,我不确定这里甚至会发生什么。它适用于开发,但不适用于生产。

这是我的架构文件:

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

  create_table "appointments", force: :cascade do |t|
    t.string   "task"
    t.datetime "time"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

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

  create_table "cycles", force: :cascade do |t|
    t.string   "title"
    t.datetime "completed_at"
    t.boolean  "completed"
    t.integer  "tray_id"
    t.datetime "created_at",   null: false
    t.datetime "updated_at",   null: false
    t.datetime "due_date"
  end

  add_index "cycles", ["tray_id"], name: "index_cycles_on_tray_id"

  create_table "datalogs", force: :cascade do |t|
    t.integer  "tray_id"
    t.float    "ambcur"
    t.float    "ambmin"
    t.float    "ambmax"
    t.float    "folcur"
    t.float    "folmin"
    t.float    "folmax"
    t.float    "ph"
    t.float    "heatmat"
    t.float    "h202"
    t.float    "tds"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  add_index "datalogs", ["tray_id"], name: "index_datalogs_on_tray_id"

  create_table "events", force: :cascade do |t|
    t.string   "name"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "grows", force: :cascade do |t|
    t.string   "title"
    t.text     "notes"
    t.datetime "created_at",  null: false
    t.datetime "updated_at",  null: false
    t.integer  "category_id"
    t.integer  "user_id"
  end

  create_table "images", force: :cascade do |t|
    t.string   "file_id"
    t.integer  "plant_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string   "tray_id"
  end

  add_index "images", ["plant_id"], name: "index_images_on_plant_id"

  create_table "nutrient_calcs", force: :cascade do |t|
    t.string   "product"
    t.integer  "vegtime"
    t.integer  "flowertime"
    t.float    "rezsize"
    t.string   "rezunits"
    t.boolean  "aerstone"
    t.string   "outputunits"
    t.integer  "nutrient_id"
    t.datetime "created_at",  null: false
    t.datetime "updated_at",  null: false
  end

  add_index "nutrient_calcs", ["nutrient_id"], name: "index_nutrient_calcs_on_nutrient_id"

  create_table "nutrients", force: :cascade do |t|
    t.string   "title"
    t.string   "manufacturer"
    t.float    "price"
    t.string   "unit"
    t.datetime "created_at",   null: false
    t.datetime "updated_at",   null: false
  end

  create_table "pages", force: :cascade do |t|
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "pics", force: :cascade do |t|
    t.string   "title"
    t.text     "description"
    t.datetime "created_at",  null: false
    t.datetime "updated_at",  null: false
  end

  create_table "plant_cycles", force: :cascade do |t|
    t.string   "title"
    t.integer  "interval"
    t.integer  "frequency"
    t.integer  "plant_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  add_index "plant_cycles", ["plant_id"], name: "index_plant_cycles_on_plant_id"

  create_table "plantdats", force: :cascade do |t|
    t.float    "ambtemp"
    t.float    "foltempcur"
    t.float    "foltempmin"
    t.float    "foltempmax"
    t.float    "ph"
    t.float    "heatmat"
    t.integer  "tds"
    t.float    "h202"
    t.integer  "plant_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.float    "ambtempmin"
    t.float    "ambtembmax"
  end

  add_index "plantdats", ["plant_id"], name: "index_plantdats_on_plant_id"

  create_table "plants", force: :cascade do |t|
    t.string   "title"
    t.text     "notes"
    t.integer  "category_id"
    t.datetime "created_at",  null: false
    t.datetime "updated_at",  null: false
    t.string   "species"
    t.integer  "tray_id"
    t.integer  "species_id"
    t.integer  "user_id"
  end

  add_index "plants", ["category_id"], name: "index_plants_on_category_id"
  add_index "plants", ["tray_id"], name: "index_plants_on_tray_id"
  add_index "plants", ["user_id"], name: "index_plants_on_user_id"

  create_table "schedules", force: :cascade do |t|
    t.integer  "schedulable_id"
    t.string   "schedulable_type"
    t.date     "date"
    t.time     "time"
    t.string   "rule"
    t.string   "interval"
    t.text     "day"
    t.text     "day_of_week"
    t.datetime "until"
    t.integer  "count"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  create_table "species", force: :cascade do |t|
    t.string   "name"
    t.text     "description"
    t.integer  "plant_id"
    t.datetime "created_at",  null: false
    t.datetime "updated_at",  null: false
  end

  add_index "species", ["plant_id"], name: "index_species_on_plant_id"

  create_table "tasks", force: :cascade do |t|
    t.integer  "plant_id"
    t.integer  "tray_id"
    t.string   "title"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.datetime "due_date"
  end

  add_index "tasks", ["plant_id"], name: "index_tasks_on_plant_id"
  add_index "tasks", ["tray_id"], name: "index_tasks_on_tray_id"

  create_table "tray_cycles", force: :cascade do |t|
    t.string   "title"
    t.integer  "tray_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  add_index "tray_cycles", ["tray_id"], name: "index_tray_cycles_on_tray_id"

  create_table "trays", force: :cascade do |t|
    t.string   "title"
    t.text     "notes"
    t.integer  "category_id"
    t.datetime "created_at",  null: false
    t.datetime "updated_at",  null: false
    t.integer  "user_id"
    t.integer  "rescap"
  end

  add_index "trays", ["category_id"], name: "index_trays_on_category_id"

  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.integer  "user_id"
    t.string   "firstname"
    t.string   "lastname"
    t.string   "username"
  end

  add_index "users", ["email"], name: "index_users_on_email", unique: true
  add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true

end

另外,我的应用程序被推送到Heroku,但是当我去'sign_up'时,我从heroku日志中得到错误:

2016-05-22T07:53:31.678059+00:00 app[web.1]: ActionView::Template::Error (undefined method `firstname' for #<User:0x007fa667e33798>):
2016-05-22T07:53:31.678049+00:00 app[web.1]: 
2016-05-22T07:53:31.678060+00:00 app[web.1]:     25: 
2016-05-22T07:53:31.678061+00:00 app[web.1]:     26:           <div class="field">
2016-05-22T07:53:31.678062+00:00 app[web.1]:     27:             <%= f.label 'First Name' %><br />
2016-05-22T07:53:31.678063+00:00 app[web.1]:     28:             <%= f.text_field :firstname, autofocus: true, rows: 10, cols: 10, class: 'form-control', placeholder: 'ENTER FIRST NAME' %>
2016-05-22T07:53:31.678064+00:00 app[web.1]:     29:           </div>
2016-05-22T07:53:31.678065+00:00 app[web.1]:     30: 
2016-05-22T07:53:31.678065+00:00 app[web.1]:     31:           <div class="field">

任何人都可以帮我解决这个问题吗?非常感谢:))

2 个答案:

答案 0 :(得分:2)

显然其中一个迁移文件丢失了 如果迁移目录已满或与数据库不一致,则可以使用rake db:schema:load直接创建整个数据库。

答案 1 :(得分:0)

感谢评论中的@xyious。不知何故,一些迁移​​被删除,我不知道。正在运行heroku run rake db:schema:load 解决了这个问题。