I was seeding a development postgres database with a few thousand records from Faker when I caught a problem with the seed file. I aborted the seed operation and rolled back the inserts and fixed the seeds.rb file.
When I went to run it again, every rake db:*
task runs twice. I can run rake routes
just fine but if I run rake db:drop
I get something like this:
$ rake db:drop
Dropped database 'vp_development'
Dropped database 'vp_development'
If I try to run migrate the whole thing blows up when it tries to apply indexes, since it's already created those columns.
I've only got the one default Rakefile, and no custom rake files in lib or anywhere else.
The environment is rails 5.0.0.1 and ruby 2.2.2 if that makes any difference. I'm so lost over this right now.
Here is my Rakefile
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require_relative 'config/application'
Rails.application.load_tas
I've seen other threads suggesting it could be a problem with a gem, but I hadn't added a new gem in a few days when this problem started. Here's the gemfile anyway.
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
gem 'puma', '~> 3.0'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'jquery-rails'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'devise'
gem 'bootstrap-sass', '3.3.6'
gem 'pg'
gem 'friendly_id'
gem 'will_paginate'
gem 'faker'
group :development, :test do
#gem 'sqlite3'
gem 'byebug', platform: :mri
end
group :development do
gem 'web-console'
gem 'listen', '~> 3.0.5'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :production do
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Edit: I also tried a custom task in the db namespace and it works fine. Only runs once. From what I can tell, db:drop, db:create, db:reset, db:migrate are the only tasks running twice. Here's a trace on db:drop
and another on db:create
.
$ rake db:drop --trace
** Invoke db:drop (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Invoke db:check_protected_environments (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config
** Execute db:check_protected_environments
** Execute db:drop
** Invoke db:drop:_unsafe (first_time)
** Invoke db:load_config
** Execute db:drop:_unsafe
Dropped database 'vp_development'
Dropped database 'vp_development'
rake db:create --trace
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:create
Created database 'vp_development'
Database 'vp_development' already exists
I found the culprit. Somewhere in the last few git commits, my database.yml was somehow duplicated.
Every time I tried to run any rake command that referenced the environment, it would run twice. Such a strange issue. Glad I was able to solve it.