I have an app on Heroku and need to clean up the database there, again run all (edited) migrations (in the migrations are added the default rows into the table) with the new default rows.
I ran
heroku run rake db:reset
this command cleared up the database, but didn’t add the new rows into the tables. I am trying to add the new lines this way:
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
...columns definitions...
t.timestamps
end
end
def self.up
Users.new(:name => 'my name', :password => 'super-secret-pass')
end
end
But the new user is not added. What am I missing?
Migrations should have one of:
changemethod.upanddownmethods (preferably instance methods in 3+ but class methods are fine too).You have a
changemethod and aself.upmethod. The migration system looks forchangefirst:so your
self.upwill never get run.Two solutions immediately present themselves:
upanddownmethods. You might want to review the guide’s Using Models in Your Migrations section.I’d probably go with 2.