Hi
I am using postgres and have two migration files like
001_create_categories.rb as
class CreateCategories < ActiveRecord::Migration
def self.up
create_table :categories do |t|
t.column :name, :string, :limit=>80
end
end
def self.down
drop_table :categories
end
end
and 002_populate_categories.rb
class PopulateCategories < ActiveRecord::Migration
execute ''ALTER SEQUENCE categories_id_seq RESTART WITH 100;''
NAMES = ["Category 1", "Category 2", "Category
3"]
def self.up
NAMES.each{|name| Category.create(:name => name)}
end
def self.down
NAMES.each{|name| Category.find_by_name(name).destroy}
end
end
My problem is if I seperately done these migrations ie one by one
everything is ok .I get sequence starts with 100 and the values like
100 Category1
101 Category2
102 Category3
But if I just migrate two migrations at once I get error
-- execute("ALTER SEQUENCE categories_id_seq RESTART WITH 100;")
rake aborted!
RuntimeError: ERROR C42P01 Mrelation "categories_id_seq" does not
exist Fnamespace.c L273 RRangeVarGetRelid: ALTER SEQUENCE
categories_id_seq RESTART WITH 100;
Could you please tell why this happens?
Thanks in advance
Sijo
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Hi Still I could not solve this problem Sijo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 14 Nov 2008, at 04:17, Sijo Kg wrote:> > Hi > I am using postgres and have two migration files like > 001_create_categories.rb as > class CreateCategories < ActiveRecord::Migration > def self.up > create_table :categories do |t| > t.column :name, :string, :limit=>80 > end > end > > def self.down > drop_table :categories > end > end > and 002_populate_categories.rb > > class PopulateCategories < ActiveRecord::Migration > execute ''ALTER SEQUENCE categories_id_seq RESTART WITH 100;'' > NAMES = ["Category 1", "Category 2", "Category 3"] > def self.up > NAMES.each{|name| Category.create(:name => name)} > end > > def self.down > NAMES.each{|name| Category.find_by_name(name).destroy} > endMove that execute into the self.up method: where it currently is, it is executed when the file is loaded. Since ActiveRecord loads all the migrations to run up front it will run that execute before migration 1 as run. Fred> > end > > My problem is if I seperately done these migrations ie one by one > everything is ok .I get sequence starts with 100 and the values like > 100 Category1 > 101 Category2 > 102 Category3 > But if I just migrate two migrations at once I get error > > -- execute("ALTER SEQUENCE categories_id_seq RESTART WITH 100;") > rake aborted! > RuntimeError: ERROR C42P01 Mrelation "categories_id_seq" does not > exist Fnamespace.c L273 RRangeVarGetRelid: ALTER SEQUENCE > categories_id_seq RESTART WITH 100; > > Could you please tell why this happens? > > Thanks in advance > Sijo > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Thanks for your reply Sijo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---