gpt4 book ai didi

ruby-on-rails - AddIndexToUsersEmail 之后的 "An error has occurred, this and all later migrations canceled"

转载 作者:太空宇宙 更新时间:2023-11-03 17:48:10 36 4
gpt4 key购买 nike

我正在关注 RailsTutorial关于建模用户的电子书(第 6 章)。我正在尝试通过运行此命令为用户电子邮件添加索引:

rails generate migration add_index_to_users_email

哪个给我 db/migrate/[timestamp]_add_index_to_users_email.rb 文件:

class AddIndexToUsersEmail < ActiveRecord::Migration
def change
add_index :users, :email, unique: true # I add this line
end
end

但是当我尝试运行 bundle exec rake db:migrate 命令时,我在终端中得到了这个:

== 20150612073526 AddIndexToUsersEmail: migrating =============================
-- add_index(:users, :email, {:unique=>true})
-> 0.0015s
== 20150612073526 AddIndexToUsersEmail: migrated (0.0016s) ====================

rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::BusyException: database is locked: commit transaction/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/statement.rb:108:in `step'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/statement.rb:108:in `block in each'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/statement.rb:107:in `loop'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/statement.rb:107:in `each'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:149:in `map'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:149:in `block in execute'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:95:in `prepare'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:134:in `execute'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:517:in `commit'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:361:in `block in commit_db_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `block in log'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract_adapter.rb:460:in `log'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:361:in `commit_db_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:155:in `commit'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:179:in `commit_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:198:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/transactions.rb:220:in `transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:1041:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:956:in `block in migrate'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:952:in `each'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:952:in `migrate'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `up'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:798:in `migrate'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked: commit transaction
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/statement.rb:108:in `step'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/statement.rb:108:in `block in each'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/statement.rb:107:in `loop'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/statement.rb:107:in `each'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:149:in `map'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:149:in `block in execute'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:95:in `prepare'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:134:in `execute'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:517:in `commit'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:361:in `block in commit_db_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `block in log'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract_adapter.rb:460:in `log'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:361:in `commit_db_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:155:in `commit'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:179:in `commit_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:198:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/transactions.rb:220:in `transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:1041:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:956:in `block in migrate'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:952:in `each'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:952:in `migrate'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `up'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:798:in `migrate'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
SQLite3::BusyException: database is locked
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/statement.rb:108:in `step'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/statement.rb:108:in `block in each'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/statement.rb:107:in `loop'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/statement.rb:107:in `each'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:149:in `map'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:149:in `block in execute'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:95:in `prepare'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:134:in `execute'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:517:in `commit'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:361:in `block in commit_db_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `block in log'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract_adapter.rb:460:in `log'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:361:in `commit_db_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:155:in `commit'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:179:in `commit_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:198:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/transactions.rb:220:in `transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:1041:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:956:in `block in migrate'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:952:in `each'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:952:in `migrate'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `up'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/migration.rb:798:in `migrate'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

顺便说一句,这是我的 Gemfile:

source 'https://rubygems.org'

gem 'rails', '4.2.0'
gem 'bootstrap-sass', '3.2.0.0'
gem 'sass-rails', '5.0.2'
gem 'uglifier', '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
gem 'turbolinks', '2.3.0'
gem 'jbuilder', '2.2.3'
gem 'sdoc', '0.4.0', group: :doc

group :development, :test do
gem 'sqlite3', '1.3.9'
gem 'byebug', '3.4.0'
gem 'web-console', '2.0.0.beta3'
gem 'spring', '1.1.3'
end

group :test do
gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace', '0.1.3'
gem 'guard-minitest', '2.3.1'
end

group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
end

如何解决这个问题?

最佳答案

这与 session 问题有关,请检查其他 session 是否打开了 rails s 或 rails c。关闭它们将解决问题。

关于ruby-on-rails - AddIndexToUsersEmail 之后的 "An error has occurred, this and all later migrations canceled",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30798068/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com