时间:2016-09-28 10:08:03

标签: ruby-on-rails web-applications sqlite database-migration

我只是尝试迁移,但我的控制台会返回此

  

StandardError:发生了错误,此错误以及稍后的所有迁移   取消:

     

SQLite3 :: SQLException:重复的列名:encrypted_pa​​ssword:   ALTER TABLE"用户" ADD" encrypted_pa​​ssword" varchar DEFAULT''不   NULL

据我所知,我不小心创建了两次表,并且必须在迁移文件中进行更改?如果是这样,我在哪里可以找到它? 在我的情况下,删除整个数据库也是一个很好的解决方案。

我只需要知道如何。到目前为止,我找到的所有解决方案对我都没有用。

更新: 当我做的时候

  

rake db:migrate:down VERSION = 20160914093125

控制台说

  

== 20160914093125 DeviseCreateUsers:还原================================    - remove_index(:users,{:column =>:reset_password_token}) - > 0.0013s    - remove_index(:users,{:column =>:email}) - > 0.0006s    - drop_table(:用户) - > 0.0003s   == 20160914093125 DeviseCreateUsers:还原(0.0025s)=======================

这些是我应该改变的吗?

3123(...)devise_create_user.rb

class DeviseCreateUsers < ActiveRecord::Migration[5.0]
  def change
    create_table :users do |t|
      ## Database authenticatable
      t.string :email,              null: false, default: ""
      t.string :encrypted_password, null: false, default: ""

      ## Recoverable
      t.string   :reset_password_token
      t.datetime :reset_password_sent_at

      ## Rememberable
      t.datetime :remember_created_at

      ## Trackable
      t.integer  :sign_in_count, default: 0, null: false
      t.datetime :current_sign_in_at
      t.datetime :last_sign_in_at
      t.string   :current_sign_in_ip
      t.string   :last_sign_in_ip

      ## Confirmable
      # t.string   :confirmation_token
      # t.datetime :confirmed_at
      # t.datetime :confirmation_sent_at
      # t.string   :unconfirmed_email # Only if using reconfirmable

      ## Lockable
      # t.integer  :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
      # t.string   :unlock_token # Only if unlock strategy is :email or :both
      # t.datetime :locked_at


      t.timestamps null: false
    end

    add_index :users, :email,                unique: true
    add_index :users, :reset_password_token, unique: true
    # add_index :users, :confirmation_token,   unique: true
    # add_index :users, :unlock_token,         unique: true
  end
end
尝试迁移后

控制台:

  

== 20160915185631 AddDeviseToUsers:迁移=================================    - change_table(:用户)   耙子流产了!   StandardError:发生错误,此以及所有后续迁移都已取消:

SQLite3 :: SQLException:没有这样的表:users:ALTER TABLE&#34; users&#34;添加&#34;电子邮件&#34; varchar DEFAULT&#39;&#39;不是NULL /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in initialize' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in new&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in prepare' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:134:in执行&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:232:in block in execute' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:566:in阻止日志&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/notifications/instrumenter.rb:21:in instrument' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:560:in log&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:232:in execute' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:547:in add_column&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:373:in add_column' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:475:in栏&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:181:in block in string' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:181:in每个&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:181:in string' /Users/matthiascordes/code/recipe_box/db/migrate/20160915185631_add_devise_to_users.rb:5:in阻止向上&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:443:in change_table' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:845:in block in method_missing&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:814:in block in say_with_time' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:814:in say_with_time&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:834:in method_missing' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:596:in method_missing&#39; /Users/matthiascordes/code/recipe_box/db/migrate/20160915185631_add_devise_to_users.rb:3:in up' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:751:in up&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:791:in exec_migration' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:772:in阻止(2级)迁移&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:771:in block in migrate' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in with_connection&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:770:in migrate' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:950:in migrate&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1211:in block in execute_migration_in_transaction' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1279:in阻止ddl_transaction&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in block in transaction' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/transaction.rb:189:in within_new_transaction&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in transaction' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:211:in transaction&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1279:in ddl_transaction' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1210:in execute_migration_in_transaction&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1183:in block in migrate_without_lock' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1182:in每个&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1182:in migrate_without_lock' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1133:in migrate&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1005:in up' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:983:in migrate&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:161:in migrate' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/railties/databases.rake:58:in阻止(2级)&# 39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/exe/rake:27:in <top (required)>' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in eval&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in <main>' ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: users: ALTER TABLE "users" ADD "email" varchar DEFAULT '' NOT NULL /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in初始化&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in new' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in准备&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:134:in execute' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:232:in阻止执行&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:566:in block in log' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/notifications/instrumenter.rb:21:in instrument&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:560:in log' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:232:in执行&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:547:in add_column' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:373:in add_column&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:475:in column' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:181:in阻止字符串&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:181:in each' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:181:in string&#39; /Users/matthiascordes/code/recipe_box/db/migrate/20160915185631_add_devise_to_users.rb:5:in block in up' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:443:in change_table&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:845:in block in method_missing' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:814:in阻止在say_with_time&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:814:in say_with_time' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:834:in method_missing&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:596:in method_missing' /Users/matthiascordes/code/recipe_box/db/migrate/20160915185631_add_devise_to_users.rb:3:in up&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:751:in up' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:791:in exec_migration&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:772:in block (2 levels) in migrate' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:771:in阻止迁移&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in with_connection' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:770:in migrate&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:950:in migrate' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1211:in块中的execute_migration_in_transaction&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1279:in block in ddl_transaction' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in阻止交易&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/transaction.rb:189:in within_new_transaction' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in transaction&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:211:in transaction' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1279:in ddl_transaction&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1210:in execute_migration_in_transaction' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1183:in阻止在migrate_without_lock&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1182:in each' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1182:in migrate_without_lock&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1133:in migrate' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1005:in up&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:983:in migrate' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:161:in migrate&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/railties/databases.rake:58:in block (2 levels) in <top (required)>' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/exe/rake:27:in&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in eval' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in&#39; SQLite3 :: SQLException:没有这样的表:users /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in initialize' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in new&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in prepare' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:134:in执行&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:232:in block in execute' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:566:in阻止日志&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/notifications/instrumenter.rb:21:in instrument' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:560:in log&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:232:in execute' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:547:in add_column&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:373:in add_column' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:475:in栏&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:181:in block in string' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:181:in每个&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:181:in string' /Users/matthiascordes/code/recipe_box/db/migrate/20160915185631_add_devise_to_users.rb:5:in阻止向上&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:443:in change_table' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:845:in block in method_missing&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:814:in block in say_with_time' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:814:in say_with_time&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:834:in method_missing' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:596:in method_missing&#39; /Users/matthiascordes/code/recipe_box/db/migrate/20160915185631_add_devise_to_users.rb:3:in up' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:751:in up&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:791:in exec_migration' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:772:in阻止(2级)迁移&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:771:in block in migrate' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in with_connection&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:770:in migrate' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:950:in migrate&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1211:in block in execute_migration_in_transaction' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1279:in阻止ddl_transaction&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in block in transaction' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/transaction.rb:189:in within_new_transaction&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in transaction' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:211:in transaction&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1279:in ddl_transaction' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1210:in execute_migration_in_transaction&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1183:in block in migrate_without_lock' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1182:in每个&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1182:in migrate_without_lock' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1133:in migrate&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1005:in up' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:983:in migrate&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:161:in migrate' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/railties/databases.rake:58:in阻止(2级)&# 39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/exe/rake:27:in <top (required)>' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in eval&#39; /Users/matthiascordes/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in`&#39;

2 个答案:

答案 0 :(得分:0)

如果您知道要恢复的迁移文件,请使用此

For eg, if this is the migration file,
20123219103503_add_name_field_to_user.rb

然后复制文件中的数字,然后在终端提示符

中运行以下命令
rake db:migrate:down VERSION=20123219103503

在迁移文件中制作版本,然后运行

rake db:migrate

来自终端

答案 1 :(得分:0)

您可能已手动修改了数据库架构或更改了正在运行的迁移文件。

如果您不需要数据库中的数据,rake db:reset将从头开始重新运行所有迁移。

您还可以尝试使用命令rake db:migrate VERSION=0将数据库迁移到版本0,然后运行rake db:migrate

如果要按照声明删除整个数据库,可以执行以下任一操作:

  

rake db:drop只会丢弃整个数据库。

     

rake db:reset db:migrate将重置您的数据库并重新加载   当前架构。

     

rake db:drop db:create db:migrate会破坏您的数据库   然后创建它,然后迁移您当前的架构。

在上述3种情况下,所有数据都将丢失。

您还可以在迁移文件中注释掉该方法,然后运行rake db:migrate,如下所示:

正常迁移文件:

class AddEncryptedPaddwordToUsers < ActiveRecord::Migration
  def change
    add_column :users, :encrypted_password, :string
  end
end

只需注释掉该方法但离开该类,所以它将是:

class AddEncryptedPaddwordToUsers < ActiveRecord::Migration
  # def change
  #   add_column :users, :encrypted_password, :string
  # end
end

然后运行rake db:migrate。基本上这是一个解决方法,告诉rails跳过迁移