I am very new to RoR and mySQL, so please excuse my ignorance. I am having a problem creating a mySQL table via migration. I am using OReillys Ruby on Rails- Up and Running book as a guide and I am stuck on page 39. The author is inserting rows into a table called slideshows, slides and photos. However I am unable to insert any data into row one of the photos table because I already have done so. So I deleted the whole table and migrated to VERSION=0 and then migrated back up in hoping that the photos table would have been recreated. However it hasnt, but the slideshows and slides tables have been recreated in this migration process. Why hasnt photos table been recreated? Any suggestions? Also you can view all of the pages I gone thru in the link below. Just click on the book with the ibex (wild goat) on it. http://books.google.com/books?q=ruby+on+rails&btnG=Search+Books&as_brr=0 Thanks for your time! -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi On page 37 and 38 I can see the migrations for slideshow and slides tables. I dont see a migration for photos...do you have a migration for the photos table? If so, can you paste the code so we can have a look. If you only have 3 migrations, paste al 3. Ivor On 2/23/07, Marc Marcus <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I am very new to RoR and mySQL, so please excuse my ignorance. > > I am having a problem creating a mySQL table via migration. I am using > O''Reilly''s "Ruby on Rails- Up and Running" book as a guide and I am > stuck on page 39. The author is inserting rows into a table called > ''slideshows'', ''slides'' and ''photos''. However I am unable to insert any > data into row one of the photos table because I already have done so. > So I deleted the whole table and migrated to VERSION=0 and then migrated > back up in hoping that the ''photos'' table would have been recreated. > However it hasn''t, but the ''slideshows'' and ''slides'' tables have been > recreated in this migration process. Why hasn''t ''photos'' table been > recreated? > > Any suggestions? > > Also you can view all of the pages I gone thru in the link below. Just > click on the book with the ibex (wild goat) on it. > http://books.google.com/books?q=ruby+on+rails&btnG=Search+Books&as_brr=0 > > Thanks for your time! > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Below are the three files that create the 3 tables. So I will do the following command; rake migrate VERSION=0; I will see it drop the other two tables (slideshow and slides). Kept in mind I manually deleted photos so I am not excepting to see photos being dropped at this point. But when I migrate back up by doing this; rake migrate VERSION=3; I ONLY see the other two tables being created. I do check this in mySQL by using the show tables command. <!001_create_photos.rb--> class CreatePhotos < ActiveRecord::Migration def self.up create_table "photos" do |photo| photo.column "filename", :string end end def self.down drop_table "photos" end end <!002_create_slideshows.rb--> class CreateSlideshows < ActiveRecord::Migration def self.up create_table "slideshows" do |t| t.column "name", :string t.column "created_at", :datetime end end def self.down drop_table "slideshows" end end <!003_create_slides.rb--> class CreateSlides < ActiveRecord::Migration def self.up create_table "slides" do |t| t.column "position", :integer t.column "photo_id", :integer t.column "slideshow_id", :integer end end def self.down drop_table "slides" end -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The one difference I note is that you are using create_table "photos" do |photo| photo.column "filename", :string end where in the other tables |t| is used. Is it possible that photo is used somewhere else? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks Joe for your feedback, however that didnt solve the problem. Below are my traces when I do the following migrating. So it seems that it attempts to drop the table photos but it throws an error. And when I attempt to create it by migrating back up, it fails silently. <!MIGRATE BACK-DOWN --> <!-- rake migrate VERSION=0; --> == CreateSlides: reverting =======================-- drop_table("slides") -> 0.1200s == CreateSlides: reverted (0.1200s) ================ == CreateSlideshows: reverting ===================-- drop_table("slideshows") -> 0.0400s == CreateSlideshows: reverted (0.0400s) ============ == CreatePhotos: reverting ======================-- drop_table("photos") rake aborted! Mysql::Error: #42S02Unknown table ''photos'': DROP TABLE photos <!MIGRATE BACK-UP --> <!-- rake migrate VERSION=3; --> == CreateSlideshows: migrating =================-- create_table("slideshows") -> 0.1500s == CreateSlideshows: migrated (0.1500s) ========== == CreateSlides: migrating ====================-- create_table("slides") -> 0.1200s == CreateSlides: migrated (0.1200s) ============== -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
What''s Rails version are you using?? 2007/2/24, __ myIP <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > > Thanks Joe for your feedback, however that didn''t solve the problem. > Below are my traces when I do the following migrating. So it seems that > it attempts to drop the table ''photos'' but it throws an error. And when > I attempt to create it by migrating back up, it fails silently. > > <!MIGRATE BACK-DOWN --> > <!-- rake migrate VERSION=0; --> > == CreateSlides: reverting =======================> -- drop_table("slides") > -> 0.1200s > == CreateSlides: reverted (0.1200s) ================> > == CreateSlideshows: reverting ===================> -- drop_table("slideshows") > -> 0.0400s > == CreateSlideshows: reverted (0.0400s) ============> > == CreatePhotos: reverting ======================> -- drop_table("photos") > rake aborted! > Mysql::Error: #42S02Unknown table ''photos'': DROP TABLE photos > > > > <!MIGRATE BACK-UP --> > <!-- rake migrate VERSION=3; --> > == CreateSlideshows: migrating =================> -- create_table("slideshows") > -> 0.1500s > == CreateSlideshows: migrated (0.1500s) ==========> > == CreateSlides: migrating ====================> -- create_table("slides") > -> 0.1200s > == CreateSlides: migrated (0.1200s) ==============> > > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Weverton Gomes de Morais Tecnólogo em Redes de Comunicação Desenvolvedor Delphi --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Below is part of the output I got when I did "gem list --local". I am using this version of rails because the authors are also using this version for the book. rails (1.1.6, 0.12.1) Web-application framework with template engine, control-flow layer, and ORM. rake (0.7.1) Ruby based make-like utility. -- 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 -~----------~----~----~----~------~----~------~--~---
In your database, is there any table after you run rake migrate VERSION=0?? Ignore schema_info table. 2007/2/25, __ myIP <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > > Below is part of the output I got when I did "gem list --local". I am > using this version of rails because the authors are also using this > version for the book. > > > rails (1.1.6, 0.12.1) > Web-application framework with template engine, control-flow layer, > and ORM. > > rake (0.7.1) > Ruby based make-like utility. > > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Weverton Gomes de Morais Tecnólogo em Redes de Comunicação Desenvolvedor Delphi --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for your time Weverton, I appreciate it! To answer your question, no. This is the output; +------------------------------+ | Tables_in_photos_development | +------------------------------+ | schema_info | +------------------------------+ 1 row in set (0.00 sec) -- 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 -~----------~----~----~----~------~----~------~--~---
OK, What''s the value o field version of schema_info table?? What''s the field value after you run rake migrate?? 2007/2/25, __ myIP <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > > Thanks for your time Weverton, I appreciate it! To answer your > question, no. This is the output; > > +------------------------------+ > | Tables_in_photos_development | > +------------------------------+ > | schema_info | > +------------------------------+ > 1 row in set (0.00 sec) > > > > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Weverton Gomes de Morais Tecnólogo em Redes de Comunicação Desenvolvedor Delphi --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> > What''s the value o field version of schema_info table?? What''s the field > value after you run rake migrate?? >I am not sure what exactly you are asking. I am not sure what field version means or how to look inside of schema_info. However the code below is from schema.rb file. I noticed when I migrate to version 0 the Date Modified field in Windows doesnt change. But when I migrate up to version 3 the Date Modified field does change. However when it migrates up to version 3 it does not change any data inside of it. It just resaves it, I am assuming. So the code inside the file never changes between versions. Does this answer your question? Thanks. <!-- schema.rb --> ActiveRecord::Schema.define(:version => 3) do create_table "slides", :force => true do |t| t.column "position", :integer t.column "photo_id", :integer t.column "slideshow_id", :integer end create_table "slideshows", :force => true do |t| t.column "name", :string t.column "created_at", :datetime end end -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Did you try erase this file and run rake migrate again?? 2007/2/25, __ myIP <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > > > > > What''s the value o field version of schema_info table?? What''s the field > > value after you run rake migrate?? > > > > > I am not sure what exactly you are asking. I am not sure what ''field > version'' means or how to look inside of schema_info. > > However the code below is from ''schema.rb'' file. I noticed when I > migrate to version 0 the ''Date Modified'' field in Windows doesn''t > change. But when I migrate up to version 3 the ''Date Modified'' field > does change. However when it migrates up to version 3 it does not > change any data inside of it. It just resaves it, I am assuming. So > the code inside the file never changes between versions. > > Does this answer your question? Thanks. > > > <!-- schema.rb --> > ActiveRecord::Schema.define(:version => 3) do > > create_table "slides", :force => true do |t| > t.column "position", :integer > t.column "photo_id", :integer > t.column "slideshow_id", :integer > end > > create_table "slideshows", :force => true do |t| > t.column "name", :string > t.column "created_at", :datetime > end > > end > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Weverton Gomes de Morais Tecnólogo em Redes de Comunicação Desenvolvedor Delphi --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Did you try erase this file and run rake migrate again??Yes, i just did. It auto-generates the same file, same code. -- 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 -~----------~----~----~----~------~----~------~--~---
I had a similar problem. I did a "rake db:migrate VERSION=0" and then deleted the schema.rb file. I then did a normal "rake db:migrate" and everything worked fine. Jim On Feb 26, 6:22 pm, __ myIP <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Did you try erase this file and run rake migrate again?? > > Yes, i just did. It auto-generates the same file, same code. > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Hmmm...that didn''t work for me, but thanks for the suggestion! I will keep that in mind next time I run into a rake problem. What I am trying to do should work, correct? I am not doing anything out of the norm am I? -- 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 -~----------~----~----~----~------~----~------~--~---
anyone!? -- 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 -~----------~----~----~----~------~----~------~--~---
I have found that running a development server (./scripts/server) while doing migrations can help as the SQL statements being generated and the DB servers responses appear in the logs. This can help track down errors. On Mar 1, 12:20 pm, __ myIP <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> anyone!? > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Thanks askegg for the feedback however I was unable to run the development server. I redid the whole project and it works fine now. I believe that when I manually deleted the table in mySql it must have done something that prevented Rails from correctly doing a migrate. -- 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 -~----------~----~----~----~------~----~------~--~---