我在Mac OS X上使用我的本地环境和Rails 4。
尝试运行迁移时,它未运行。
我收到以下输出:
*******-C02MGBVJFD57:myapp *************$ bundle exec rake db:migrate
Your Gemfile lists the gem faker (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
Your Gemfile lists the gem factory_girl_rails (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
== 20140815221246 AddPasswordDigestToUsers: migrating =========================
-- add_column(:users, :password_digest, :string)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: Duplicate column name 'password_digest': ALTER TABLE `users` ADD `password_digest` varchar(255)/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `query'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `block in execute'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activesupport-4.1.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `execute'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/mysql2_adapter.rb:228:in `execute'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:375:in `add_column'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:649:in `block in method_missing'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `block in say_with_time'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `say_with_time'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:641:in `method_missing'
/Users/*************/workspace/myapp/db/migrate/20140815221246_add_password_digest_to_users.rb:3:in `change'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:595:in `exec_migration'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:578:in `block in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:577:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:752:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:1040:in `ddl_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:953:in `block in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `each'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `up'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:785:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
ActiveRecord::StatementInvalid: Mysql2::Error: Duplicate column name 'password_digest': ALTER TABLE `users` ADD `password_digest` varchar(255)
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `query'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `block in execute'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activesupport-4.1.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `execute'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/mysql2_adapter.rb:228:in `execute'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:375:in `add_column'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:649:in `block in method_missing'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `block in say_with_time'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `say_with_time'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:641:in `method_missing'
/Users/*************/workspace/myapp/db/migrate/20140815221246_add_password_digest_to_users.rb:3:in `change'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:595:in `exec_migration'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:578:in `block in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:577:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:752:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:1040:in `ddl_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:953:in `block in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `each'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `up'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:785:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
Mysql2::Error: Duplicate column name 'password_digest'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `query'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `block in execute'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activesupport-4.1.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `execute'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/mysql2_adapter.rb:228:in `execute'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:375:in `add_column'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:649:in `block in method_missing'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `block in say_with_time'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `say_with_time'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:641:in `method_missing'
/Users/*************/workspace/myapp/db/migrate/20140815221246_add_password_digest_to_users.rb:3:in `change'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:595:in `exec_migration'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:578:in `block in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:577:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:752:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:1040:in `ddl_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:953:in `block in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `each'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `up'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:785:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
知道出了什么问题吗?
编辑: 下面用户表的架构:
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_digest"
end
用户迁移:
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.string :password_digest
t.timestamps
end
end
end
class AddPasswordDigestToUsers < ActiveRecord::Migration
def change
add_column :users, :password_digest, :string
end
end
class AddRememberDigestToUsers < ActiveRecord::Migration
def change
add_column :users, :remember_digest, :string
end
end
答案 0 :(得分:0)
问题正在发生,因为在您的CreateUsers
迁移中,您已经创建了一个users
表,其中包含password_digest
列,如下所示:
t.string :password_digest
然后,在AddPasswordDigestToUsers
迁移中,您尝试向users
表添加具有相同名称的列:
add_column :users, :password_digest, :string
这是迁移失败的错误Mysql2::Error: Duplicate column name 'password_digest'
。
您确定需要AddPasswordDigestToUsers
文件吗?它看起来并不像,因为您已在CreateUsers
迁移中添加了该列。
我认为您只需删除AddPasswordDigestToUsers
迁移文件,然后尝试重新运行bundle exec rake db:migrate
。