rails: rails db:migrate db:seed cannot be run in the same command as of v5.1
Steps to reproduce
- Create a new Rails project with postgresql.
- Add a migration that creates a table.
echo 'ApplicationRecord.connection.reconnect!' > db/seeds.rb
- Run
rails db:create db:migrate db:seed
Expected behavior
Finishes without errors.
Actual behavior
Hangs on Rails 5.1.1. Works on Rails 5.0.3.
System configuration
Rails version: 5.1.1 Ruby version: 2.4.1
Another way to reproduce (without reconnect!
)
-
Create a
User
model and table with aname
field. -
Add this snippet to the user model
def name=(value) super(value) end
-
echo 'User.create(name: "Joe")' > db/seeds.rb
-
rails db:create db:migrate db:seed
💥 error, no superclass methodname=
defined.
Running rails db:create db:migrate
and then rails db:seed
works in both cases.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 15 (6 by maintainers)
Commits related to this issue
- Seed database in separate bin/rails call This should avoid https://github.com/rails/rails/issues/29112, which we've all hit while setting things up — committed to King-County-Equity-Now/decidim-seattle by mshenfield 4 years ago
- Seed database in separate bin/rails call (#45) * Ignore config/heroku_config.rb This file is intended to hold sensitive credentials, and should not be added to version control. Perfect for .gitignor... — committed to King-County-Equity-Now/decidim-seattle by mshenfield 4 years ago
- Fix review apps v2 (#338) Fix post deploy hook issue (db:seed crashes) which could be due to https://github.com/rails/rails/issues/29112 --------- Co-authored-by: Matthieu Faugere <matthieu.fa... — committed to betagouv/mon-suivi-justice by cmarcoin a year ago
After a load of fiddling, I managed to resolve by adding
at the top of my seeds.rb
This solution worked for my scenario, Rails v5.2.4.1 👍
This still happens. As in 5.1, I have to run
rails db:migrate && rails db:seed
instead ofrails db:migrate db:seed
. It seemsdb:seed
caches the column info somehow.@andrehjr You’re right, I’ve just tried to reproduce it in a standalone Rails app and it works.
However, for some reason that I haven’t been able to isolate yet (spring?), it does not work in this case: