rails: rails db:migrate db:seed cannot be run in the same command as of v5.1

Steps to reproduce

  1. Create a new Rails project with postgresql.
  2. Add a migration that creates a table.
  3. echo 'ApplicationRecord.connection.reconnect!' > db/seeds.rb
  4. 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!)

  1. Create a User model and table with a name field.

  2. Add this snippet to the user model

    def name=(value)
      super(value)
    end
    
  3. echo 'User.create(name: "Joe")' > db/seeds.rb

  4. rails db:create db:migrate db:seed 💥 error, no superclass method name= 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

Most upvoted comments

After a load of fiddling, I managed to resolve by adding

ApplicationRecord.reset_column_information

at the top of my seeds.rb

After a load of fiddling, I managed to resolve by adding

ApplicationRecord.reset_column_information

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 of rails db:migrate db:seed. It seems db: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:

git clone https://github.com/thredded/thredded_create_app
cd thredded_create_app
git checkout c26b25953af56db1082e58478311cf84fea787ed
bundle
bin/create-tmp-myapp