1

I just realized that when I run rails c I'm getting a different database than when I run rails db.

I initially though the console wasn't connecting to the database at all because it kept returning empty sets, for instance when running User.all, despite having seed data. I then inserted data into the database via the console and did a query from the SQLite console. The new data did not appear even after reloading the console.

My confusion is further exacerbated by the fact that I only have the db/development.sqlite3 file and rails r "puts Rails.env" returns Development.

So where might I have gone wrong here? Why is one using the development database and the other seemingly using something else? Could rake db:seed be pushing to Test perhaps? Is there a way to check the SQLite console for the environment?

1 Answer 1

2

Turns out Spring was causing the problem. I had a previous app with the same name and it was loading that when I opened the rails console despite being in the newer app directory.

I've disabled Spring with the DISABLE_SPRING variable and now things are working as expected.

Sign up to request clarification or add additional context in comments.

1 Comment

Having the same issue. Save me about 30mins. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.