Skip to content

Instantly share code, notes, and snippets.

@kenmazaika
Last active January 27, 2017 19:23
Show Gist options
  • Save kenmazaika/ee96bf96faf81fc3b605990a0d435e16 to your computer and use it in GitHub Desktop.
Save kenmazaika/ee96bf96faf81fc3b605990a0d435e16 to your computer and use it in GitHub Desktop.

Rebuilding Your Database.

Unfortunately databases migrations will only run a single time for a given environment (once for localhost / once for heroku). That means that once it ran the migration, it added the picture column to the users table and that it was done. Any time you run "rake db:migrate" again it doesn't know that the migration changed so it won't do anything.

You may want to revisit this video, for more in-depth details about database migrations.

So rule of thumb: never edit a migration after you run it.

When your database is out of sync with the rules that we wrote to build them up. Often times the easiest thing to do will be to tear down your database and put it back up. You will lose all you user/places/etc but by running all of them start to finish again you won't run the migration in the intermediate state.

First, stop your server and any rails consoles.

Second, run this command (and make sure you don't see any error messages when you run it):

rake db:drop

Third, run this command

rake db:create

Fourth, run this command:

rake db:migrate

After running each of these commands you'll have successfully rebuilt your database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment