I want to create a migration file that creates multiple tables, so i''m
guessing the correct format would be:
Can anyone confirm ? I''m guessing that each new create script requires
a
seperate class so formatted this way. Perhaps I''m wrong.
TIA
Stuart
class CreateTable1 < ActiveRecord::Migration
def self.up
create_table :table1s do |t|
t.column :length, :string
end
end
def self.down
drop_table :table1s
end
end
class CreateTable2 < ActiveRecord::Migration
def self.up
create_table :table2s do |t|
t.column :length, :string
end
end
def self.down
drop_table :table2s
end
end
class CreateTable3 < ActiveRecord::Migration
def self.up
create_table :table3s do |t|
t.column :length, :string
end
end
def self.down
drop_table :table3s
end
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/15c51335/attachment.html
Maybe you should try it and see? I can''t help you because I honestly don''t know, but I do know how I would proceed. Dark Ambient wrote:> I want to create a migration file that creates multiple tables, so i''m > guessing the correct format would be:-- Posted via http://www.ruby-forum.com/.
It didn''t work. Stuart On 6/13/06, Jim <fijimf@gmail.com> wrote:> > Maybe you should try it and see? > > I can''t help you because I honestly don''t know, but I do know how I > would proceed. > > Dark Ambient wrote: > > I want to create a migration file that creates multiple tables, so i''m > > guessing the correct format would be: > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/a4328923/attachment.html
Actually only the first table was created. Stuart On 6/13/06, Dark Ambient <sambient@gmail.com> wrote:> > It didn''t work. > > Stuart > > > On 6/13/06, Jim <fijimf@gmail.com> wrote: > > > > Maybe you should try it and see? > > > > I can''t help you because I honestly don''t know, but I do know how I > > would proceed. > > > > Dark Ambient wrote: > > > I want to create a migration file that creates multiple tables, so i''m > > > > > guessing the correct format would be: > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/fe1e759a/attachment.html
You can only have one set of self.up/self.down methods in a migration class, and only one class per file, but you can create, destroy, or modify multiple tables in each up and down. So, you''d want something like:> class CreateTables < ActiveRecord::Migration > def self.up > create_table :table1s do |t| > t.column :length, :string > end > create_table :table2s do |t| > t.column :length, :string > end > create_table :table3s do |t| > t.column :length, :string > end > end > > def self.down > drop_table :table1s > drop_table :table2s > drop_table :table3s > end > end >-- Posted via http://www.ruby-forum.com/.
On 6/13/06, Dark Ambient <sambient@gmail.com> wrote:> Actually only the first table was created.You can put multiple table definition blocks into a single class declaration. When the migration is called, it only calls the migration class that corresponds to the migration file name... Remember, convention over configuration. ;) -Curtis
Jay, thanks actually right before your email came through that is what I had
come up with:
Only it''s not working, not coughing errors but not working. I usually
run
through the IDE RadRails, and received just a
(in C:/InstantRails/rails_apps/lfw)
So I went into the rails console (script/console) and I guess that might
have not been a good idea. I ran rake migrate and got back:
** Invoke migrate (first_time)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
** Invoke db:schema:dump (first_time)
** Invoke environment
** Execute db:schema:dump
** Execute migrate
Yet, this was not the first time I ran rake migrate. So I tried it again in
the cosole but added --trace and got back:
(in C:/InstantRails/rails_apps/lfw)
No tables were created though.
Here is the migration file I created.
class CreateTables < ActiveRecord::Migration
def self.up
create_table :postlengths do |t|
t.column :postlength, :string
end
create_table :expreqs do |t|
t.column :expreq, :string
end
create_table :edureqs do |t|
t.column :edureq, :string
end
create_table :contactmethods do |t|
t.column :contactmethod, :string
end
create_table :securityclears do |t|
t.column :securityclear, :string
end
end
def self.down
drop_table :postlengths
drop_table :expreqs
drop_table :edureqs
drop_table :contactmethods
drop_table :securityclears
end
end
Not sure what''s going on.
Stuart
On 6/13/06, Jay <j-zeschin@northwestern.edu>
wrote:>
> You can only have one set of self.up/self.down methods in a migration
> class, and only one class per file, but you can create, destroy, or
> modify multiple tables in each up and down. So, you''d want
something
> like:
>
> > class CreateTables < ActiveRecord::Migration
> > def self.up
> > create_table :table1s do |t|
> > t.column :length, :string
> > end
> > create_table :table2s do |t|
> > t.column :length, :string
> > end
> > create_table :table3s do |t|
> > t.column :length, :string
> > end
> > end
> >
> > def self.down
> > drop_table :table1s
> > drop_table :table2s
> > drop_table :table3s
> > end
> > end
> >
>
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/d95245f8/attachment.html
Stop the presses ! I got it to work. Don''t ask how :) Format is the same. Thank you, Stuart On 6/13/06, Jay <j-zeschin@northwestern.edu> wrote:> > You can only have one set of self.up/self.down methods in a migration > class, and only one class per file, but you can create, destroy, or > modify multiple tables in each up and down. So, you''d want something > like: > > > class CreateTables < ActiveRecord::Migration > > def self.up > > create_table :table1s do |t| > > t.column :length, :string > > end > > create_table :table2s do |t| > > t.column :length, :string > > end > > create_table :table3s do |t| > > t.column :length, :string > > end > > end > > > > def self.down > > drop_table :table1s > > drop_table :table2s > > drop_table :table3s > > end > > end > > > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/667687aa/attachment.html
Jay, Wasn''t sure if I thanked you for the help, so thank you! Stuart On 6/13/06, Jay <j-zeschin@northwestern.edu> wrote:> > You can only have one set of self.up/self.down methods in a migration > class, and only one class per file, but you can create, destroy, or > modify multiple tables in each up and down. So, you''d want something > like: > > > class CreateTables < ActiveRecord::Migration > > def self.up > > create_table :table1s do |t| > > t.column :length, :string > > end > > create_table :table2s do |t| > > t.column :length, :string > > end > > create_table :table3s do |t| > > t.column :length, :string > > end > > end > > > > def self.down > > drop_table :table1s > > drop_table :table2s > > drop_table :table3s > > end > > end > > > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/11a78f68/attachment.html
I ran into a migration snag again. I''ve googled around and come up with
a
few things but none that specifically show my scenario. I''m tryint to
migrate data into multiple tables at once.
Tried a few different ways with no success -
I get this error:
:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:123:in
`rake_original_const_missing'': uninitialized constant Postlength
(NameError)
Postlength.create = Postlength is the singular name of the table postlengths
:postlength is the column name in the table.
This is part of the file:
class Addstaticdata < ActiveRecord::Migration
def self.up
Postlength.create(:postlength => ''7 Days'')
Postlength.create(:postlength => ''14 Days'')
Postlength.create(:postlength => ''21 Days'')
Postlength.create(:postlength => ''30 Days'')
Postlength.create(:postlength => ''45 Days'')
Postlength.create(:postlength => ''60 Days'')
Edureq.create(:edureq => ''PhD'')
Edureq.create(:edureq => ''Juris Doctorate'')
Edureq.create(:edureq => ''Trade School'')
Contactmethod.create(:contactmethod => ''Direct through
details'')
Contactmethod.create(:contactmethod => ''Through
website'')
Contactmethod.create(:contactmethod => ''Both direct and
website'')
Securityclear.create(:securityclear => ''None'')
Securityclear.create(:securityclear => ''Active
Confidential'')
Securityclear.create(:securityclear => ''Active Top
Secret'')
Securityclear.create(:securityclear => ''Active Top Secret
SCI'')
end
def self.down
end
end
Hope I''m not being a pain here.
Stuart
On 6/13/06, Dark Ambient <sambient@gmail.com>
wrote:>
> Jay,
> Wasn''t sure if I thanked you for the help, so thank you!
>
> Stuart
>
> On 6/13/06, Jay <j-zeschin@northwestern.edu > wrote:
>
> > You can only have one set of self.up/self.down methods in a migration
> > class, and only one class per file, but you can create, destroy, or
> > modify multiple tables in each up and down. So, you''d want
something
> > like:
> >
> > > class CreateTables < ActiveRecord::Migration
> > > def self.up
> > > create_table :table1s do |t|
> > > t.column :length, :string
> > > end
> > > create_table :table2s do |t|
> > > t.column :length, :string
> > > end
> > > create_table :table3s do |t|
> > > t.column :length, :string
> > > end
> > > end
> > >
> > > def self.down
> > > drop_table :table1s
> > > drop_table :table2s
> > > drop_table :table3s
> > > end
> > > end
> > >
> >
> >
> > --
> > Posted via http://www.ruby-forum.com/.
> > _______________________________________________
> > Rails mailing list
> > Rails@lists.rubyonrails.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/15061b4a/attachment-0001.html
Have you created a Postlength model yet? You''ll need that to populate your table. -- Posted via http://www.ruby-forum.com/.
Ahh, okay Jay ..thank you. I was thinking about that possibly being the cause but left that out of my experiments. Thank you again, I owe you ! Stuart On 6/13/06, Jay <j-zeschin@northwestern.edu> wrote:> > Have you created a Postlength model yet? You''ll need that to populate > your table. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/2ba7f18a/attachment.html