【发布时间】:2020-12-10 04:14:04
【问题描述】:
您能帮我弄清楚我还需要在这里编辑或更改哪些内容吗? 我有任务应用程序,并且有 3 个模型类别、用户和任务,它们已经相关。如果您想在这里查看我的模型,该应用程序在我的本地机器上运行良好:
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
has_many :tasks
has_many :categories
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
end
class Task < ApplicationRecord
belongs_to :category
belongs_to :user
validates :title, presence: true,
length: { minimum: 3 }
validates :details, length: { minimum: 5 }
end
class Category < ApplicationRecord
has_many :tasks, :dependent => :destroy
belongs_to :user
validates :name, presence: true, uniqueness: true
end
是的!这就是我的模型的样子。
我能够在 heroku 上 deoply 我的应用程序,然后我运行这个:
heroku run rake db:migrate
并收到此错误消息:
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedColumn: ERROR: column "user_id" of relation "tasks" does not exist
我检查了我的 schema.rb 和 user_id uder tasks 表。
ActiveRecord::Schema.define(version: 2020_12_09_004213) do
create_table "categories", force: :cascade do |t|
t.string "name"
t.text "description"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "user_id"
end
create_table "tasks", force: :cascade do |t|
t.string "title"
t.text "details"
t.integer "category_id"
t.date "set_date"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "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.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, 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```
【问题讨论】:
-
@Eyeslandic 我已经尝试过了,但我也遇到了错误。
ActiveRecord::NoEnvironmentInSchemaError: Environment data not found in the schema. To resolve this issue, run: rails db:environment:set RAILS_ENV=production当我运行 rails db:environment:set RAILS_ENV=production 我得到这个错误ArgumentError: Missing `secret_key_base` for 'production' environment, set this string with `rails credentials:edit -
你能粘贴运行`heroku run rake db:migrate`时从Heroku获得的整个错误日志吗?总的来说,我的意思是每一行
标签: ruby-on-rails heroku database-schema heroku-postgres