I just tried to migrate, but my console returns this
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: duplicate column name: encrypted_password: ALTER TABLE "users" ADD "encrypted_password" varchar DEFAULT '' NOT NULL
I understand that I accidentally created a table twice and have to do changes in my migration file? If so, where can I find it? Dropping the whole database would be a good solution, too in my case.
I just need to know how. All the solutions I found so far didn't work for me.
UPDATE: When I do
rake db:migrate:down VERSION=20160914093125
The console says
== 20160914093125 DeviseCreateUsers: reverting ================================ -- remove_index(:users, {:column=>:reset_password_token}) -> 0.0013s -- remove_index(:users, {:column=>:email}) -> 0.0006s -- drop_table(:users) -> 0.0003s == 20160914093125 DeviseCreateUsers: reverted (0.0025s) =======================
Are these the points i should change?
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
Console after trying to migrate:
== 20160915185631 AddDeviseToUsers: migrating ================================= -- change_table(:users) rake aborted! StandardError: An error has occurred, this and all later migrations canceled:
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 initialize' /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 prepare' /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 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
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' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:560: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' /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' /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
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 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
each' /Us ers/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
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' /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 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' /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' /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' /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' /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 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' /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' /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 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
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 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' /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' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/acti ve_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' /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
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' /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' /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_re cord/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
block (2 levels) in ' /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' /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
initialize' /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
prepare' /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
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
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 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' /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
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' /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_colu mn' /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
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 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' /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' /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
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
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' /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' /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' /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 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
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
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' /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' /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 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
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' /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' /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' /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 each' /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' /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' /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' /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
' /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
' SQLite3::SQLException: no such table: 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' /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
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 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
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' /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 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' /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
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 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
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' /Users/matthiascordes/code/recipe_box/db/migrate/20160915185631_add_devise_to_users.rb:5:in
string' /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' /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 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' /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' /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' /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' /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 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' /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' /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
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
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 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' /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' /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
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' /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
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' /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' /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' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/railties/databases.rake:58:in
migrate' /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 ' /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' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `'
If you know the migration file, which you want to revert back, then use this,
For eg, if this is the migration file,
20123219103503_add_name_field_to_user.rb
then copy the numbers in the file and then run the following in your terminal prompt,
rake db:migrate:down VERSION=20123219103503
make editions in the migration files, then run
rake db:migrate
from terminal
You may have modified the database schema manually or changed a migration file being run.
If you dont need the data in the database, a rake db:reset
would re-run all migrations from scratch.
You could also try to migrate your database to version 0 with command: rake db:migrate VERSION=0
and then run rake db:migrate
If you want to drop the whole database as you stated, you can do either of the following:
rake db:drop
simply drops the whole database.
rake db:reset db:migrate
will reset your database and reload the current schema.
rake db:drop db:create db:migrate
will destroy your database and then create it and then migrate your current schema.
All data will be lost in the above 3 scenarios.
You could also comment out the method in the migration file, then run rake db:migrate
as below:
Normal Migration File:
class AddEncryptedPaddwordToUsers < ActiveRecord::Migration
def change
add_column :users, :encrypted_password, :string
end
end
Just comment out the method but leave the class, so it would be:
class AddEncryptedPaddwordToUsers < ActiveRecord::Migration
# def change
# add_column :users, :encrypted_password, :string
# end
end
Then run rake db:migrate
. Essentially this is a work around that tells rails to skip the migration
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.