尝试部署到 heroku 时出错(按照 ror 教程)PG::Error: ERROR: column "password_digest" of relationship &quo
Posted
技术标签:
【中文标题】尝试部署到 heroku 时出错(按照 ror 教程)PG::Error: ERROR: column "password_digest" of relationship "users" already exists【英文标题】:Error trying to deploy to heroku (following ror tutorial) PG::Error: ERROR: column "password_digest" of relation "users" already exists 【发布时间】:2014-10-11 00:27:35 【问题描述】:所以我关注http://www.railstutorial.org/book,并且 evrything 在本地运行良好(运行 sqlight3)。
我尝试时收到以下错误
heroku 运行 rake db:migrate
这是错误消息的样子
运行
rake db:migrate
连接到终端... up, run.4049 迁移到 AddPasswordDigestToUsers (20140817014655) == 20140817014655 AddPasswordDigestToUsers:迁移 ========================= -- add_column(:users, :password_digest, :string) PG::Error: ERROR: 关系“users”的列“password_digest”已经存在:ALTER 表“用户”添加列“密码摘要”字符变化(255)耙 中止! StandardError: 发生错误,这个和以后的一切 迁移已取消:PG::Error: ERROR: 关系“users”的列“password_digest” 已经存在:ALTER TABLE "users" ADD COLUMN "password_digest" 特点 变化(255)/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in
exec' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in
block 正在执行' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/connection_adapters/abstract_adapter.rb:442:inblock in log' /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.8/lib/active_support/notifications/instrumenter.rb:20:in
instrument' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/connection_adapters/abstract_adapter.rb:437:inlog' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in
execute' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/connection_adapters/abstract/schema_statements.rb:360:inadd_column' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/connection_adapters/postgresql/schema_statements.rb:395:in
add_column' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:629:inblock in method_missing' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:601:in
block in say_with_time' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:601:insay_with_time' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:621:in
method_missing' /app/db/migrate/20140817014655_add_password_digest_to_users.rb:3:inchange' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:575:in
exec_migration' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:559:inblock (2 levels) in migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:558:in
block in 迁移' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:inwith_connection' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:557:in
migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:713:inmigrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:963:in
block 在 execute_migration_in_transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:1009:inblock in ddl_transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/connection_adapters/abstract/database_statements.rb:203:in
交易中的区块' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/connection_adapters/abstract/database_statements.rb:211:inwithin_new_transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/connection_adapters/abstract/database_statements.rb:203:in
transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/transactions.rb:209:intransaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:1009:in
ddl_transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:962:inexecute_migration_in_transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:924:in
block in 迁移' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:920:ineach' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:920:in
migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:768:inup' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:746:in
migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/railties/databases.rake:42:in '任务中的`block(2个级别):TOP => db:migrate(请参阅 通过使用 --trace 运行任务来完整跟踪)
我已经尝试过 heroku pg:reset DATABASE_URL 然后重试。 还尝试将 /spec、/lib、/script、/features、/cucumber.yml 添加到 .slugignore
这是我的架构的样子:
ActiveRecord::Schema.define(version: 20140818041701) do
create_table "users", force: true do |t|
t.string "name"
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
t.string "password_digest"
t.string "remember_token"
t.boolean "admin", default: false
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["remember_token"], name: "index_users_on_remember_token"
end
这就是我的密码摘要迁移的样子
class AddPasswordDigestToUsers < ActiveRecord::Migration
def change
add_column :users, :password_digest, :string
end
end
【问题讨论】:
【参考方案1】:您的表中已经有 password_digest
列,并且通过迁移 AddPasswordDigestToUsers
您正在尝试创建另一个列,这就是它产生问题的原因。删除迁移AddPasswordDigestToUsers
并尝试再次运行rake db:migrate
。在这种情况下,Sqlite3 不会产生任何错误。如果你在迁移中写intege
而不是integer
,如果你使用sqlite,它不会产生任何错误。
【讨论】:
【参考方案2】:如果您只是删除密码摘要迁移文件,它将解决部署到 heroku 的短期问题,但协作者将无法在本地下拉并设置他们的数据库。他们会遇到问题,并且可能会创建另一个迁移文件,从而产生同样的问题。
我不确定最好的解决方案,但到目前为止这似乎对我有用:
class AddPasswordDigestToUsers < ActiveRecord::Migration
def change
if Rails.env == "production"
else
add_column :users, :password_digest, :string
end
end
end
【讨论】:
以上是关于尝试部署到 heroku 时出错(按照 ror 教程)PG::Error: ERROR: column "password_digest" of relationship &quo的主要内容,如果未能解决你的问题,请参考以下文章
使用 SQLite 3 将 RoR 应用程序部署到 Heroku 失败
尝试将 react.js 应用程序部署到 heroku 时出错