首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误试图部署到heroku (下面的教程) PG:: Error : ERROR:列"password_digest“的关系”用户“已经存在

错误试图部署到heroku (下面的教程) PG:: Error : ERROR:列"password_digest“的关系”用户“已经存在
EN

Stack Overflow用户
提问于 2014-08-18 06:27:38
回答 2查看 374关注 0票数 1

因此,我正在跟踪http://www.railstutorial.org/book,并且在本地(运行sqlight3)工作正常。

当我尝试时,我会得到以下错误

heroku运行rake db:

这就是错误消息的样子。

运行连接到终端的rake db:migrate .运行4049迁移到AddPasswordDigestToUsers ( 20140817014655 ) == 20140817014655 AddPasswordDigestToUsers:迁移========================= -- add_column(:users,:password_digest,:string) PG::Error:列"password_digest“的关系”用户“已经存在: ALTER "users”添加列"password_digest“字符变化(255个) rake中止!StandardError:发生了一个错误,随后的迁移都被取消了: 错误:错误:关系“用户”的列"password_digest“已经存在: ALTER "users”在execute‘/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.中添加列"password_digest“字符exec' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in块0.8/lib/active_record/connection_adapters/abstract_adapter.rb:442:in block in log' /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.8/lib/active_support/notifications/instrumenter.rb:20:in仪器‘/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/connection_adapters/abstract_adapter.rb:437:in log' /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//app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:629:in add_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‘schema_statements.rb:360:in block in method_missing' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:601:in block in method_missing' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:601:in in say_with_time’/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:601:in say_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:in change' /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:in block (2 levels) in migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:558:in块/ with_connection' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:557:in:294:在with_connection' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:557:in中迁移‘execute_migration_in_transaction’migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:963:in块中的execute_migration_in_transaction‘block 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:in within_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:in transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:1009:in ddl_transaction‘/app/供应商/bundle/ruby/2.0迁移中的.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:962:in execute_migration_in_transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:924:in块‘/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:920:in each' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:920:in迁移’/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:768:在“任务”中的“/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/railties/databases.rake:42:in”块(2个级别)中:up' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:746:in迁移:=> db:up' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:746:in(请参见通过使用-- trace运行任务的完整跟踪)

我已经尝试过heroku :重置DATABASE_URL,然后再尝试。还尝试将/spec、/lib、/script、/features、/cucumber.yml添加到.slugignore中

这就是我的模式的样子:

代码语言:javascript
复制
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

这就是我的密码摘要迁移的样子。

代码语言:javascript
复制
class AddPasswordDigestToUsers < ActiveRecord::Migration
  def change
    add_column :users, :password_digest, :string
  end
end
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-08-18 07:22:26

您的表中已经有了password_digest列,通过迁移AddPasswordDigestToUsers,您正在尝试创建另一个列,这就是它造成问题的原因。删除迁移AddPasswordDigestToUsers,然后再次运行rake db:migrate。在这种情况下,Sqlite3不会产生任何错误。如果在迁移中编写intege而不是integer,那么如果使用sqlite,就不会产生任何错误。

票数 0
EN

Stack Overflow用户

发布于 2016-04-27 13:37:24

如果您只是删除密码摘要迁移文件,它将解决部署到heroku的短期问题,但是协作者将无法在本地提取和设置他们的数据库。它们将遇到问题,并可能会创建另一个迁移文件,从而产生同样的问题。

我不确定最好的解决方案,但到目前为止,这似乎对我来说是可行的:

代码语言:javascript
复制
class AddPasswordDigestToUsers < ActiveRecord::Migration
  def change
    if Rails.env == "production"
    else
      add_column :users, :password_digest, :string   
    end
  end
end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25357421

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档