因此,我正在跟踪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:inblock 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:inlog' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:inexecute’/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:inadd_column' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/connection_adapters/postgresql/schema_statements.rb:395:inadd_column‘schema_statements.rb:360:inblock in method_missing' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:601:inblock in method_missing' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.8/lib/active_record/migration.rb:601:inin 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:inmethod_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:inexec_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块/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: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:intransaction’/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:inddl_transaction‘/app/供应商/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块‘/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迁移’/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中
这就是我的模式的样子:
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发布于 2014-08-18 07:22:26
您的表中已经有了password_digest列,通过迁移AddPasswordDigestToUsers,您正在尝试创建另一个列,这就是它造成问题的原因。删除迁移AddPasswordDigestToUsers,然后再次运行rake db:migrate。在这种情况下,Sqlite3不会产生任何错误。如果在迁移中编写intege而不是integer,那么如果使用sqlite,就不会产生任何错误。
发布于 2016-04-27 13:37:24
如果您只是删除密码摘要迁移文件,它将解决部署到heroku的短期问题,但是协作者将无法在本地提取和设置他们的数据库。它们将遇到问题,并可能会创建另一个迁移文件,从而产生同样的问题。
我不确定最好的解决方案,但到目前为止,这似乎对我来说是可行的:
class AddPasswordDigestToUsers < ActiveRecord::Migration
def change
if Rails.env == "production"
else
add_column :users, :password_digest, :string
end
end
endhttps://stackoverflow.com/questions/25357421
复制相似问题