Resetting the database in Rails 4

So I made a new branch in git to continue my rails study as suggested in Michael Hartl’s 3rd edition. I used rails console to create a new user so that I could setup the user page (at this time we did not have the sign up form). So per instructions it says

Since we’re about to add the ability to create new users through the
web, let’s remove the user created at the console in Section 6.3.4.
The cleanest way to do this is to reset the database with bundle exec rake db:migrate:reset

I was under the impression that db:reset is suppose to dump the current database and rebuild it from the schema.rb, but for me it deletes everything in my schema leaving it blank and I have to copy an earlier version of my schema from another branch.

Is there something I’m not doing correctly or overlooking? I thought I understood the db::xxxx commands but apparently not as well as I fooled myself into thinking ha.

  • Can't push my code to heroku master
  • Cannot push my ruby app to heroku
  • How to git pull without overwriting database data
  • Merging two branches, one with Postgres and another with SQLite3
  • Subclipse error “svn: SQLite compiled for 3.8.6, but running with 3.8.5”
  • Rails: Populate Heroku database with development.sqlite3 data
  • Git pull problems with gitignore
  • Rails app using sqlite3 for development won't deploy into heroku
  • One Solution collect form web for “Resetting the database in Rails 4”

    Nope, this is the expected behavior. The test data resets every time you run the tests unless you provide seed date. You should check out Factory Girl to build objects for your test database: https://github.com/thoughtbot/factory_girl

    Hartl covers Factory Girl later in the book/tutorial, so you might not have gotten to that part yet.

    So you are partially correct; rake db:reset will rebuild your schema, but all the data will be destroyed. It’s a bad idea to use a copy of an existing database for testing purposes.

    To rebuild the schema I usually run:

    rake db:test:prepare
    

    Works every time.

    Git Baby is a git and github fan, let's start git clone.