I’m not sure if this is the right way but during development i often do rake db:drop and rake db:migrate to rebuild my DB from scratch (so i dont have 100000 migration files)
I’m wondering how I create 3 default objects (the 3 Category objects of my app). Also an admin user, so I dont need to add them via rails console every time. it would be nice just to have it be smoother when I deploy it to production as well
What you are looking for is
rake db:seed. Inside of the db directory there is a file calledseeds.rb. You can fill this file with as much code as you need to create and populate your database with whatever you want. Ryan Bates’ Railscasts, Episode #179 covers this topic in great detail.On a side note, I often find it useful to create a bash alias so I don’t have to go through all three commands every time. In your bash profile just add:
Then in you terminal you only have to type
migrateto get back up and running.