Hello, I have a problem understanding Rails/Rake migrations. For example let''s say I have a migrate-script like this: class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.string :name t.string :username t.string :password t.string :email t.timestamps end User.create :name=>"John Smith", :email=>"js-b6s7PLiH4D04Q++5jOxPmw@public.gmane.org", :username=>"js", :password="jsRules!" end def self.down drop_table :users end end If I do a migration with db:reset it will update all tables, DELETE EVERYTHING, and then insert John Smith. However, let''s say I want to add a t.string :secret_answer to that model, and migrate it, what do I use? I would like to keep all data already in DB and just have rake add one column to the table. I tried migrate:redo, migrate.up etc. The latter even requires a Version value. What do I enter here? Now this is obviously a very noobish question, but maybe one of you can clarify. FYI, I''m using latest RoR with Aptana on Windows7 and mySQL as DB- backend. Thanks, Lukas -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 17 February 2010 13:12, lukas <lukas.zielinski-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hello, > > I have a problem understanding Rails/Rake migrations. > > For example let''s say I have a migrate-script like this: > > class CreateUsers < ActiveRecord::Migration > def self.up > create_table :users do |t| > t.string :name > t.string :username > t.string :password > t.string :email > t.timestamps > end > > User.create :name=>"John > Smith", :email=>"js-b6s7PLiH4D04Q++5jOxPmw@public.gmane.org", :username=>"js", :password="jsRules!" > end > > def self.down > drop_table :users > end > end > > > If I do a migration with db:reset it will update all tables, DELETE > EVERYTHING, and then insert John Smith. > > However, let''s say I want to add a > > t.string :secret_answer > > to that model, and migrate it, what do I use? > > I would like to keep all data already in DB and just have rake add one > column to the table. > > > I tried migrate:redo, migrate.up etc. The latter even requires a > Version value. What do I enter here?To apply migrations that have not already been applied use rake db:migrate http://guides.rubyonrails.org/ has a guide on migrations, but start with Getting Started if you have not already worked through that. Then work through the others. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin, Thanks. You know, I first looked at Rails one year ago and knew this. But somehow I forgot it. Thanks for pointing knucklehead-me back to the basics. :) I basically create new migrations and then db:migrate works like a charm. Thanks! On 17 Feb., 14:38, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 17 February 2010 13:12, lukas <lukas.zielin...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > > > Hello, > > > I have a problem understanding Rails/Rake migrations. > > > For example let''s say I have a migrate-script like this: > > > class CreateUsers < ActiveRecord::Migration > > def self.up > > create_table :users do |t| > > t.string :name > > t.string :username > > t.string :password > > t.string :email > > t.timestamps > > end > > > User.create :name=>"John > > Smith", :email=>"j...-b6s7PLiH4D04Q++5jOxPmw@public.gmane.org", :username=>"js", :password="jsRules!" > > end > > > def self.down > > drop_table :users > > end > > end > > > If I do a migration with db:reset it will update all tables, DELETE > > EVERYTHING, and then insert John Smith. > > > However, let''s say I want to add a > > > t.string :secret_answer > > > to that model, and migrate it, what do I use? > > > I would like to keep all data already in DB and just have rake add one > > column to the table. > > > I tried migrate:redo, migrate.up etc. The latter even requires a > > Version value. What do I enter here? > > To apply migrations that have not already been applied use > rake db:migrate > > http://guides.rubyonrails.org/has a guide on migrations, but start > with Getting Started if you have not already worked through that. > Then work through the others. > > Colin-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.