# Rake migrate- problems

**URL:** <https://www.ruby-forum.com/t/rake-migrate-problems/86537>\
**Category:** Rails\
**Created:** [February 23, 2007, 3:18am UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537 "2007-02-23T03:18:30Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [February 23, 2007, 3:18am UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/1 "2007-02-23T03:18:30Z")

</div>

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](http://books.google.com/books?q=ruby+on+rails&btnG=Search+Books&as_brr=0)

Thanks for your time!

---

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [February 23, 2007, 9:46am UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/2 "2007-02-23T09:46:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [February 24, 2007, 1:20am UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/3 "2007-02-24T01:20:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [February 24, 2007, 4:30am UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/4 "2007-02-24T04:30:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [February 25, 2007, 3:08pm UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/5 "2007-02-25T15:08:55Z")

</div>

What’s Rails version are you using??

2007/2/24, \_\_ myIP [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> – drop\_table(“slides”)  
> rake aborted!
> 
> >

–  
Weverton G. de Morais  
TecnÃ³logo em Redes de ComunicaÃ§Ã£o  
Desenvolvedor Delphi

---

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [February 25, 2007, 5:29pm UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/6 "2007-02-25T17:29:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [February 24, 2007, 4:01pm UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/7 "2007-02-24T16:01:16Z")

</div>

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 --\>

== 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 --\>

== CreateSlideshows: migrating ==================  
– create\_table(“slideshows”)  
-\> 0.1500s  
== CreateSlideshows: migrated (0.1500s) ===========

== CreateSlides: migrating =====================  
– create\_table(“slides”)  
-\> 0.1200s  
== CreateSlides: migrated (0.1200s) ===============

---

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [February 25, 2007, 5:47pm UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/8 "2007-02-25T17:47:48Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [February 25, 2007, 5:34pm UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/9 "2007-02-25T17:34:14Z")

</div>

In your database, is there any table after you run rake migrate  
VERSION=0??  
Ignore schema\_info table.

2007/2/25, \_\_ myIP [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> rake (0.7.1)  
> Ruby based make-like utility.
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Weverton G. de Morais  
TecnÃ³logo em Redes de ComunicaÃ§Ã£o  
Desenvolvedor Delphi

---

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [February 25, 2007, 6:13pm UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/10 "2007-02-25T18:13:21Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 1 row in set (0.00 sec)
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Weverton G. de Morais  
TecnÃ³logo em Redes de ComunicaÃ§Ã£o  
Desenvolvedor Delphi

---

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [February 26, 2007, 5:55pm UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/11 "2007-02-26T17:55:23Z")

</div>

Did you try erase this file and run rake migrate again??

2007/2/25, \_\_ myIP [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> ```
> t.column "created_at", :datetime
> 
> ```
> 
> end
> 
> end
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Weverton G. de Morais  
TecnÃ³logo em Redes de ComunicaÃ§Ã£o  
Desenvolvedor Delphi

---

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [February 27, 2007, 1:22am UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/12 "2007-02-27T01:22:32Z")

</div>

> Did you try erase this file and run rake migrate again??

Yes, i just did. It auto-generates the same file, same code.

---

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [February 25, 2007, 9:52pm UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/13 "2007-02-25T21:52:05Z")

</div>

> 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.

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

---

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [February 28, 2007, 1:40am UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/14 "2007-02-28T01:40:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [February 27, 2007, 7:09pm UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/15 "2007-02-27T19:09:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [March 1, 2007, 2:44am UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/16 "2007-03-01T02:44:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [March 1, 2007, 2:20am UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/17 "2007-03-01T02:20:17Z")

</div>

anyone!?

---

<div class="post-metadata">

**Author:** ![myip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@myip](https://www.ruby-forum.com/u/myip)\
**Post date:** [March 10, 2007, 4:05am UTC](https://www.ruby-forum.com/t/rake-migrate-problems/86537/18 "2007-03-10T04:05:08Z")

</div>

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.
