我一直试图在一周的大部分时间里修复这个db bug。任何帮助表示赞赏;寻找任何解决方案,无论多么激烈。
问题出现是因为我的架构中没有表的“库存”的迁移文件。我在不同的功能分支中创建了表“stock”,无论出于何种原因,此迁移文件在合并后都没有返回到主分支。所以没有create_stocks迁移文件,但有几个add_column_to_stocks迁移文件。
所以我尝试重新排序我的迁移文件但是没有用,所以我清理了我的迁移文件并运行了rake db:migrate:reset,所以在我的生产方面一切都很好。如果我在我的生产端运行rake db:migrate,我没有错误,但当我尝试将其推送到heroku时,我得到一个奇怪的消息。它似乎仍然希望迁移不再存在的迁移文件。
以下是完整的信息:
Called from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-
4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
ActiveRecord::SchemaMigration Load (1.6ms) SELECT "schema_migrations".*
FROM "schema_migrations"
Migrating to AddLatestPriceToStocks (20180515064500)
(1.1ms) BEGIN
== 20180515064500 AddLatestPriceToStocks: migrating
===========================
-- add_column(:stocks, :latest_price, :decimal)
(1.9ms) ALTER TABLE "stocks" ADD "latest_price" decimal
(1.1ms) ROLLBACK
rake aborted!
StandardError: An error has occurred, this and all later migrations
canceled:
PG::UndefinedTable: ERROR: relation "stocks" does not exist
: ALTER TABLE "stocks" ADD "latest_price" decimal
以下是我的迁移文件;请注意,不再有20180515064500迁移文件,所以我不知道它为什么还在尝试将其迁移到heroku。
up 20171231042756 Create articles
up 20171231044214 Add description to articles
up 20180116183526 Create users
up 20180116191414 Add user to articles
up 20180116195212 Add password digest to users
up 20180305082108 Create categories
up 20180305090315 Create article categories
up 20180521021514 Create user stocks
up 20180530032220 Create stocks
这是我的本地生产模式:
create_table "article_categories", force: :cascade do |t|
t.integer "article_id"
t.integer "category_id"
end
create_table "articles", force: :cascade do |t|
t.string "title"
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
end
create_table "categories", force: :cascade do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "stocks", force: :cascade do |t|
t.decimal "latest_price"
t.string "company_name"
t.datetime "latest_time"
t.integer "latest_update"
end
create_table "user_stocks", force: :cascade do |t|
t.integer "user_id"
t.integer "stock_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "user_stocks", ["stock_id"], name: "index_user_stocks_on_stock_id"
add_index "user_stocks", ["user_id"], name: "index_user_stocks_on_user_id"
create_table "users", force: :cascade do |t|
t.string "username"
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
t.string "password_digest"
end
这是我的Heroku架构:
create_table "article_categories", force: :cascade do |t|
t.integer "article_id"
t.integer "category_id"
end
create_table "articles", force: :cascade do |t|
t.string "title"
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
end
create_table "categories", force: :cascade do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "users", force: :cascade do |t|
t.string "username"
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
t.string "password_digest"
end
end
不确定我是否让问题变得更糟。无论多么激烈,我都在寻找任何解决方案。任何帮助表示赞赏,希望这是足够的信息。