Ok, going through the book Ruby on Rails Made Easy, and I made a
mistake here. I forgot to add in two columns into my table. so i tried
to add them back into the migration file and run it again, but after
checking with the #ROR channel on IRC i was informed that this is not
possible. I needed to make a new migration file.
I have done this, but I am obviously doing something wrong. If someone
could point out my error it would be appreciated.
Original migration file.
class CreateCategories < ActiveRecord::Migration
def self.up
create_table :categories do |t|
t.column :name, :string
end
Category.create :name => "Furniture"
Category.create :name => "Miscellaneous"
add_column :classifieds, :category_id, :integer
Classified.find(:all).each do |c|
c.update_attribute(:category_id, 4)
end
end
def self.down
drop_table :categories
remove_column :classifieds, :category_id
end
end
Migration file I tried to create.
class AddColumns < ActiveRecord::Migration
def self.up
create_t.column :name, :string
end
Category.create :name => "Electronics"
Category.create :name => "Real Estate"
end
def self.down
drop_table :categories
remove_column :classifieds, :category_id
end
end
receive an unexpected kEND expecting $ error when trying to run rake
db:migrate on the new file.
Thank you,
Dave
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
> > > I have done this, but I am obviously doing something wrong. If someone > could point out my error it would be appreciated. > > > Migration file I tried to create. > > class AddColumns < ActiveRecord::Migration > def self.up > create_t.column :name, :string > endOops, self.up is ended here, but you continue to write migration up code, delete this end statement Category.create :name => "Electronics"> Category.create :name => "Real Estate" > end > > def self.down > drop_table :categories > remove_column :classifieds, :category_id > end > end > > receive an unexpected kEND expecting $ error when trying to run rake > db:migrate on the new file. > > Thank you, > > Dave--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You only need to create create a new migration file to add columns if you''ve already put your app into production. If you''re just following a tutorial, just edit the migration you have. Then run rake db:migrate VERSION=0 to drop everything and then rake db:migrate to set up the db again with your new migration. b wheresdave wrote:> Ok, going through the book Ruby on Rails Made Easy, and I made a > mistake here. I forgot to add in two columns into my table. so i tried > to add them back into the migration file and run it again, but after > checking with the #ROR channel on IRC i was informed that this is not > possible. I needed to make a new migration file. > > I have done this, but I am obviously doing something wrong. If someone > could point out my error it would be appreciated. > > > Original migration file. > > class CreateCategories < ActiveRecord::Migration > def self.up > create_table :categories do |t| > t.column :name, :string > end > > Category.create :name => "Furniture" > Category.create :name => "Miscellaneous" > > add_column :classifieds, :category_id, :integer > Classified.find(:all).each do |c| > c.update_attribute(:category_id, 4) > end > end > > def self.down > drop_table :categories > remove_column :classifieds, :category_id > end > end > > > Migration file I tried to create. > > class AddColumns < ActiveRecord::Migration > def self.up > create_t.column :name, :string > end > > Category.create :name => "Electronics" > Category.create :name => "Real Estate" > end > > def self.down > drop_table :categories > remove_column :classifieds, :category_id > end > end > > receive an unexpected kEND expecting $ error when trying to run rake > db:migrate on the new file. > > Thank you, > > Dave > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
awesome. thank you so much. On Apr 8, 1:00 pm, Ben Munat <bmu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You only need to create create a new migration file to add columns if > you''ve already put your app into production. > > If you''re just following a tutorial, just edit the migration you have. > Then run rake db:migrate VERSION=0 to drop everything and then rake > db:migrate to set up the db again with your new migration. > > b > > wheresdave wrote: > > Ok, going through the book Ruby on Rails Made Easy, and I made a > > mistake here. I forgot to add in two columns into my table. so i tried > > to add them back into the migration file and run it again, but after > > checking with the #ROR channel on IRC i was informed that this is not > > possible. I needed to make a new migration file. > > > I have done this, but I am obviously doing something wrong. If someone > > could point out my error it would be appreciated. > > > Original migration file. > > > class CreateCategories < ActiveRecord::Migration > > def self.up > > create_table :categories do |t| > > t.column :name, :string > > end > > > Category.create :name => "Furniture" > > Category.create :name => "Miscellaneous" > > > add_column :classifieds, :category_id, :integer > > Classified.find(:all).each do |c| > > c.update_attribute(:category_id, 4) > > end > > end > > > def self.down > > drop_table :categories > > remove_column :classifieds, :category_id > > end > > end > > > Migration file I tried to create. > > > class AddColumns < ActiveRecord::Migration > > def self.up > > create_t.column :name, :string > > end > > > Category.create :name => "Electronics" > > Category.create :name => "Real Estate" > > end > > > def self.down > > drop_table :categories > > remove_column :classifieds, :category_id > > end > > end > > > receive an unexpected kEND expecting $ error when trying to run rake > > db:migrate on the new file. > > > Thank you, > > > Dave--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---