Rake not working

75 views
Skip to first unread message

Andrew Jacobs

unread,
Apr 19, 2011, 10:26:02 AM4/19/11
to railsin...@googlegroups.com
In trying to get Rails running on a Vista SP2 machine where I'm not admin, I've turned to Railsinstaller v1.1.1 but have hit a snag--the rake tasks aren't working.  Here's what I do (from within the Railsinstaller command prompt initiated from the start menu):

1. rails new test_app
2. cd test_app
3. bundle install
4. rake db:create
5. rails generate scaffold User name:string email:string
6. rake db.migrate
7. rails server

When I go to http://localhost:3000/users, I get an error that the table User can't be found.  Upon investigation, I see that although the migration file was created correctly and the databases were created (development and test), the dev database is 0kb.  (Note: when I ran the 'rake db:migrate' I received no messages back for error or success).

So, at this point I called upon the Gods in the IRC (thanks Wayne) who helped me dig into this.  Running 'rake db:migrate --trace' showed the following:

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

but the db is still 0kb.

We then tried to run the migration manually from the rails console, which succeeded (db was now 2kb and going to http://localhost:3000/users was successful).  So the conclusion was that everything was set up correctly except rake wasn't doing its job.  The question is, why?  In the interim, I'll run migrations manually but it'd be a lot nicer to understand what's causing this issue.  (FYI, Wayne tested on Win7 and Win Vista as well and didn't experience this problem).

Thanks in advance for any insight you can offer.

Andrew

Wayne E. Seguin

unread,
Apr 19, 2011, 10:38:11 AM4/19/11
to railsin...@googlegroups.com
Luis et all, I gave this a good go via screen sharing and am at a loss for why 'rake db:migrate' would simply do nothing here...
--
  ~Wayne

Wayne E. Seguin
wayneeseguin on irc.freenode.net

Luis Lavena

unread,
Apr 19, 2011, 10:44:26 AM4/19/11
to railsin...@googlegroups.com
On Tue, Apr 19, 2011 at 11:26 AM, Andrew Jacobs <andrew...@gmail.com> wrote:
> In trying to get Rails running on a Vista SP2 machine where I'm not admin,
> I've turned to Railsinstaller v1.1.1 but have hit a snag--the rake tasks
> aren't working.  Here's what I do (from within the Railsinstaller command
> prompt initiated from the start menu):

Hello Andrew, can you answer some questions before we get into the details?

Did you install RailsInstaller with Admin rights?
Was the command prompt used to create the application elevated (admin rights)?
Is the application using sqlite3? Is Gemfile defining it properly?
(gem "sqlite3")

> So, at this point I called upon the Gods in the IRC (thanks Wayne) who
> helped me dig into this.  Running 'rake db:migrate --trace' showed the
> following:
> ** 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
> but the db is still 0kb.

And what is db/schema.rb ?

It gets created? What it contains?

> We then tried to run the migration manually from the rails console, which
> succeeded (db was now 2kb and going to http://localhost:3000/users was
> successful).  So the conclusion was that everything was set up correctly
> except rake wasn't doing its job.  The question is, why?  In the interim,
> I'll run migrations manually but it'd be a lot nicer to understand what's
> causing this issue.  (FYI, Wayne tested on Win7 and Win Vista as well and
> didn't experience this problem).

I'll try to reproduce this locally and let you know. I haven't tested
out Rails 3.0.3 or greater, so need to check what could have changed
or what could be affecting.

Will create a test application from scratch to try out.

--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry

Andrew Jacobs

unread,
Apr 19, 2011, 10:59:14 AM4/19/11
to railsin...@googlegroups.com
Hi Luis,

Thanks for the reply.  I've put the answers below.

On Tue, Apr 19, 2011 at 10:44 AM, Luis Lavena <luisl...@gmail.com> wrote:
On Tue, Apr 19, 2011 at 11:26 AM, Andrew Jacobs <andrew...@gmail.com> wrote:
> In trying to get Rails running on a Vista SP2 machine where I'm not admin,
> I've turned to Railsinstaller v1.1.1 but have hit a snag--the rake tasks
> aren't working.  Here's what I do (from within the Railsinstaller command
> prompt initiated from the start menu):

Hello Andrew, can you answer some questions before we get into the details?

Did you install RailsInstaller with Admin rights?
 Andrew: No, I don't have admin rights on this machine.  Maybe that's the issue?

Was the command prompt used to create the application elevated (admin rights)?
Andrew: No, unfortunately, I don't have admin rights.
 
Is the application using sqlite3? Is Gemfile defining it properly?
(gem "sqlite3")
Andrew: Yes, the app is using sqlite3.  Gemfile the following line: gem 'sqlite3'. Running 'gem list sqlite3' shows version 1.3.3 x86-mingw32 and  1.2.5 x86-mingw32.


> So, at this point I called upon the Gods in the IRC (thanks Wayne) who
> helped me dig into this.  Running 'rake db:migrate --trace' showed the
> following:
> ** 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
> but the db is still 0kb.

And what is db/schema.rb ?

Andrew:
Nothing in here other than the definition:
ActiveRecord::Schema.define(:version => 0) do

end

 

It gets created? What it contains?
Andrew: see above 

Luis Lavena

unread,
Apr 19, 2011, 11:17:23 AM4/19/11
to railsin...@googlegroups.com
On Tue, Apr 19, 2011 at 11:59 AM, Andrew Jacobs <andrew...@gmail.com> wrote:
> Hi Luis,

>
>  Andrew: No, I don't have admin rights on this machine.  Maybe that's the
> issue?
>>

No, wanted to check that could be a permission issue.

>>
>> And what is db/schema.rb ?
>
> Andrew:
> Nothing in here other than the definition:
> ActiveRecord::Schema.define(:version => 0) do
> end
>

AFAIK, db:migrate lookups all the files in the db/migrate folder and
compare those with the database version_info table.

I smell there is a problem doing that lookup, si not finding these
files and thus, not generating or updating the schema.

Will dig into the code in a bit, refresh my memory, specific which
version of Rails is?

Will look into this at lunch time.

Ken Collins

unread,
Apr 19, 2011, 11:22:34 AM4/19/11
to railsin...@googlegroups.com

Just a guess. Maybe it is a RAILS_ENV setting higher up and when you are running $ rake db:migrate it is actually running under a different RAILS_ENV default like "development". Perhaps try

$ rake db:migrate RAILS_ENV=development

Again, just a wild guess.


- Ken


Andrew Jacobs

unread,
Apr 19, 2011, 11:24:36 AM4/19/11
to railsin...@googlegroups.com
On Tue, Apr 19, 2011 at 11:17 AM, Luis Lavena <luisl...@gmail.com> wrote:

> Andrew:
> Nothing in here other than the definition:
> ActiveRecord::Schema.define(:version => 0) do
> end
>

AFAIK, db:migrate lookups all the files in the db/migrate folder and
compare those with the database version_info table.

I smell there is a problem doing that lookup, si not finding these
files and thus, not generating or updating the schema.

Will dig into the code in a bit, refresh my memory, specific which
version of Rails is?

Will look into this at lunch time.

 
Thanks Luis.  I'm using the Rails 3.0.6 that comes with v1.1.1 of Railsinstaller.

Andrew Jacobs

unread,
Apr 19, 2011, 11:29:09 AM4/19/11
to railsin...@googlegroups.com
Ken,

Good thought, but explicitly setting the environment (to either development or production) doesn't seem to help.

Andrew

Wayne E. Seguin

unread,
Apr 19, 2011, 11:58:18 AM4/19/11
to railsin...@googlegroups.com
Andrew, perhaps you can put the application on github for Luis?


Andrew Jacobs

unread,
Apr 19, 2011, 12:04:49 PM4/19/11
to railsin...@googlegroups.com
Sure: g...@github.com:drewbono/test4_app.git

Luis Lavena

unread,
Apr 19, 2011, 7:51:47 PM4/19/11
to railsin...@googlegroups.com
On Tue, Apr 19, 2011 at 1:04 PM, Andrew Jacobs <andrew...@gmail.com> wrote:
> Sure: g...@github.com:drewbono/test4_app.git
>

I've recreated the application from scratch:

https://gist.github.com/68c040c189558b5f0220

Now, using your application, first:

https://gist.github.com/84523b8b64c314fa2c30

Can you provide me the full output of "dir db" ?

Also, you didn't have any previous sqlite3.dll hanging around
somewhere? what is the output of "where sqlite3.dll" ?

Thank you.

Andrew Jacobs

unread,
Apr 20, 2011, 9:48:34 AM4/20/11
to railsin...@googlegroups.com
On Tue, Apr 19, 2011 at 7:51 PM, Luis Lavena <luisl...@gmail.com> wrote:
On Tue, Apr 19, 2011 at 1:04 PM, Andrew Jacobs <andrew...@gmail.com> wrote:
> Sure: g...@github.com:drewbono/test4_app.git
>

I've recreated the application from scratch:

https://gist.github.com/68c040c189558b5f0220

Now, using your application, first:

https://gist.github.com/84523b8b64c314fa2c30

Can you provide me the full output of "dir db" ?


Also, you didn't have any previous sqlite3.dll hanging around
somewhere? what is the output of "where sqlite3.dll" ?


No, I don't have any other sqlite3.dll's.  Here' the where output:

C:\Sites>where sqlite3.dll
C:\RailsInstaller\Ruby1.8.7\bin\sqlite3.dll 

Andrew Jacobs

unread,
Apr 20, 2011, 11:24:35 AM4/20/11
to railsin...@googlegroups.com
On Wed, Apr 20, 2011 at 9:48 AM, Andrew Jacobs <andrew...@gmail.com> wrote:

Can you provide me the full output of "dir db" ?


Also, you didn't have any previous sqlite3.dll hanging around
somewhere? what is the output of "where sqlite3.dll" ?


No, I don't have any other sqlite3.dll's.  Here' the where output:

C:\Sites>where sqlite3.dll
C:\RailsInstaller\Ruby1.8.7\bin\sqlite3.dll 

Quick update on this.  Playing around with it this morning I found that the migration works fine if I explicitly tell rake to run the specific migration using the "VERSION" modifier.  But, if I run a 'rake db:migrate' thereafter, it drops the table.  Any idea what that could mean?

Here's what it looked like:



Luis Lavena

unread,
Apr 21, 2011, 6:58:58 PM4/21/11
to railsin...@googlegroups.com
On Wed, Apr 20, 2011 at 12:24 PM, Andrew Jacobs <andrew...@gmail.com> wrote:
>
> Quick update on this.  Playing around with it this morning I found that the
> migration works fine if I explicitly tell rake to run the specific migration
> using the "VERSION" modifier.  But, if I run a 'rake db:migrate' thereafter,
> it drops the table.  Any idea what that could mean?
> Here's what it looked like:
> https://gist.github.com/931620
>

Can you check the following?

C:\>SET VERSION

You should see this:

Environment variable VERSION not defined

===

Andrew Jacobs

unread,
Apr 21, 2011, 7:14:20 PM4/21/11
to railsin...@googlegroups.com

On Apr 21, 2011, at 6:58 PM, Luis Lavena wrote:

> On Wed, Apr 20, 2011 at 12:24 PM, Andrew Jacobs <andrew...@gmail.com> wrote:
>>
>> Quick update on this. Playing around with it this morning I found that the
>> migration works fine if I explicitly tell rake to run the specific migration
>> using the "VERSION" modifier. But, if I run a 'rake db:migrate' thereafter,
>> it drops the table. Any idea what that could mean?
>> Here's what it looked like:
>> https://gist.github.com/931620
>>
>
> Can you check the following?
>
> C:\>SET VERSION
>
> You should see this:
>
> Environment variable VERSION not defined

It says:

C:\> SET VERSION
Version=Win2k


Luis Lavena

unread,
Apr 21, 2011, 7:18:17 PM4/21/11
to railsin...@googlegroups.com
On Thu, Apr 21, 2011 at 8:14 PM, Andrew Jacobs <andrew...@gmail.com> wrote:
>
>
> It says:
>
> C:\> SET VERSION
> Version=Win2k
>

Dunno where is coming from, specially since you're not running Windows 2000.

Can you please unset that variable and try rake db:migrate again?

If that works, please remove that from your environment, or ask your
IT department to remove it.

If they don't want, just modify the batch file used by RailsInstaller
(Start Command Prompt with Ruby) and add:

SET VERSION=

That will clear up the version.

Andrew Jacobs

unread,
Apr 21, 2011, 7:28:41 PM4/21/11
to railsin...@googlegroups.com

On Apr 21, 2011, at 7:18 PM, Luis Lavena wrote:

> On Thu, Apr 21, 2011 at 8:14 PM, Andrew Jacobs <andrew...@gmail.com> wrote:
>>
>>
>> It says:
>>
>> C:\> SET VERSION
>> Version=Win2k
>>
>
> Dunno where is coming from, specially since you're not running Windows 2000.
>
> Can you please unset that variable and try rake db:migrate again?
>
> If that works, please remove that from your environment, or ask your
> IT department to remove it.
>
> If they don't want, just modify the batch file used by RailsInstaller
> (Start Command Prompt with Ruby) and add:
>
> SET VERSION=
>
> That will clear up the version.

Success! I have no idea why that was keeping things from working, but as soon as I modified the .bat file to set the version to nothing, all my migrations started to work, even on the test4_app project I shared earlier. Many thanks for your persistence and sharing your expertise.

Andrew

Luis Lavena

unread,
Apr 21, 2011, 7:34:53 PM4/21/11
to railsin...@googlegroups.com
On Thu, Apr 21, 2011 at 8:28 PM, Andrew Jacobs <andrew...@gmail.com> wrote:
>
>
> Success!  I have no idea why that was keeping things from working, but as soon as I modified the .bat file to set the version to nothing, all my migrations started to work, even on the test4_app project I shared earlier.  Many thanks for your persistence and sharing your expertise.
>

Awesome, the reason it was affecting from things to work is hide
inside Rake and how it works.

Arguments supplied to rake in the form of VERSION=12345 are converted
into environment variables, or used environment variables if they were
set.

Is a flaw in Rake design on how to pass arguments to tasks but since
is well spread and used, cannot be removed without breaking
*everything under the sun*

When you mentioned that explicit rake db:migrate VERSION worked, it
clicked in my brain that ENV["VERSION"] was the reason.

Once you remove the environment variable, it then let the db:migrate
task work normally.

I've tested this locally using rake db:migrate VERSION=foo

VERSION gets translated into a number, so it will be zero, and that is
reverting all existing migrations. Same happen to you, Win2k (the
VERSION value) will translate to zero, and failing.

Will be great to know from where that variable is coming from, just curious.

Regards,

nwil...@engineyard.com

unread,
Apr 21, 2011, 7:40:49 PM4/21/11
to railsin...@googlegroups.com
Bravo Luis!

Cheers
Nic

http://engineyard.com
http://drnicwilliams.com
+1 (415) 322 9556

Engine Yard: Successful Rails Apps through Orchestration

Wayne E. Seguin

unread,
Apr 25, 2011, 1:57:20 PM4/25/11
to railsin...@googlegroups.com
Luis,

Simply amazing... Thank you very much for helping out Andrew!

Andrew Jacobs

unread,
Apr 26, 2011, 10:11:09 AM4/26/11
to railsin...@googlegroups.com
Luis,

Sorry for the delay...this is my first day back in the office since last week.  Thanks again to you and Wayne for all your help.  Who would have guessed that's how rake passes arguments?  Not me. :-)

As far as the where the variable is being set in the first place, I'm assuming it must be from an old customization script (since it sets the variable to W2k) that my company still runs on logon even though they upgraded everyone to Vista a couple of years ago.  If I ever find out definitively, I'll let you know.

Best,
Andrew
Reply all
Reply to author
Forward
0 new messages