Dan Bikle
2006-Aug-04 03:43 UTC
[Rails] Demo in rails2.pdf of add_price migration, PostgreSQL 8.1.4
People, I''m looking at the migrate example on p 74 of the rails2.pdf It''s a simple example of using a migration to add a column to the products table. Here is a copy of the migration file named 002_add_price.rb after I generated and then edited it: class AddPrice < ActiveRecord::Migration def self.up add_column :products, :price, :decimal, :precision => 8, :scale => 2, :default => 0 end def self.down remove_column :products, :price end end I see this error when I walk through the demo: bash mac maco /pt/books/rails2_my_depot/depot 9 $ bash mac maco /pt/books/rails2_my_depot/depot 9 $ rake db:migrate --trace (in /pt/books/rails2_my_depot/depot) ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:migrate == AddPrice: migrating =======================================================-- add_column(:products, :price, :decimal, {:precision=>8, :scale=>2, :default=>0}) rake aborted! You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occured while evaluating nil.[] /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:259:in `type_to_sql'' /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/connection_adapters/postgresql_adapter.rb:310:in `add_column'' /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:272:in `method_missing'' /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:256:in `say_with_time'' /r/lib/ruby/1.8/benchmark.rb:293:in `measure'' /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:256:in `say_with_time'' /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:270:in `method_missing'' ./db/migrate//002_add_price.rb:3:in `real_up'' /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:210:in `migrate'' /r/lib/ruby/1.8/benchmark.rb:293:in `measure'' /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:210:in `migrate'' /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:332:in `migrate'' /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:327:in `migrate'' /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:294:in `up'' /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:285:in `migrate'' /r/lib/ruby/gems/1.8/gems/rails-1.1.4/lib/tasks/databases.rake:4 /r/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute'' /r/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute'' /r/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:in `invoke'' /r/lib/ruby/1.8/thread.rb:135:in `synchronize'' /r/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in `invoke'' /r/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run'' /r/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run'' /r/lib/ruby/gems/1.8/gems/rake-0.7.1/bin/rake:7 /r/bin/rake:18 bash mac maco /pt/books/rails2_my_depot/depot 10 $ bash mac maco /pt/books/rails2_my_depot/depot 10 $ bash mac maco /pt/books/rails2_my_depot/depot 10 $ Info about my setup: bash mac maco /pt/books/rails2_my_depot/depot 12 $ bash mac maco /pt/books/rails2_my_depot/depot 12 $ bash mac maco /pt/books/rails2_my_depot/depot 12 $ uname -a Darwin mac 8.7.0 Darwin Kernel Version 8.7.0: Fri May 26 15:20:53 PDT 2006; root:xnu-792.6.76.obj~1/RELEASE_PPC Power Macintosh powerpc bash mac maco /pt/books/rails2_my_depot/depot 13 $ bash mac maco /pt/books/rails2_my_depot/depot 13 $ bash mac maco /pt/books/rails2_my_depot/depot 13 $ [ os x 10.4 ] bash mac maco /pt/books/rails2_my_depot/depot 19 $ bash mac maco /pt/books/rails2_my_depot/depot 19 $ bash mac maco /pt/books/rails2_my_depot/depot 19 $ bash mac maco /pt/books/rails2_my_depot/depot 19 $ psql depot_development Welcome to psql 8.1.4, the PostgreSQL interactive terminal. bash mac maco /pt/books/rails2_my_depot/depot 12 $ bash mac maco /pt/books/rails2_my_depot/depot 12 $ bash mac maco /pt/books/rails2_my_depot/depot 12 $ bash mac maco /pt/books/rails2_my_depot/depot 12 $ bash mac maco /pt/books/rails2_my_depot/depot 11 $ gem list --local *** LOCAL GEMS *** actionmailer (1.2.3) Service layer for easy email delivery and testing. actionpack (1.12.3) Web-flow and rendering framework putting the VC in MVC. actionwebservice (1.1.4) Web service support for Action Pack. activerecord (1.14.3) Implements the ActiveRecord pattern for ORM. activesupport (1.3.1) Support and utility classes used by the Rails framework. postgres (0.7.1) The extension library to access a PostgreSQL database from Ruby. rails (1.1.4) Web-application framework with template engine, control-flow layer, and ORM. rake (0.7.1) Ruby based make-like utility. sources (0.0.1) This package provides download sources for remote gem installation bash mac maco /pt/books/rails2_my_depot/depot 12 $ bash mac maco /pt/books/rails2_my_depot/depot 12 $ bash mac maco /pt/books/rails2_my_depot/depot 12 $ bash mac maco /pt/books/rails2_my_depot/depot 12 $ Anyone have any clues on how I can get this to work? Thanks, -Dan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060804/494ec5a0/attachment-0001.html
Dan Bikle
2006-Aug-04 04:16 UTC
[Rails] Demo in rails2.pdf of add_price migration, PostgreSQL 8.1.4
Well, I ran a simple experiment where I tried adding a column with data type of string rather than decimal and it worked well. Then, I ran another experiment where I tried creating a table with a column with data type of decimal and it succeeded: bash mac maco /pt/books/rails2_my_depot/depot 18 $ bash mac maco /pt/books/rails2_my_depot/depot 18 $ bash mac maco /pt/books/rails2_my_depot/depot 18 $ script/generate model testdecimal exists app/models/ exists test/unit/ exists test/fixtures/ create app/models/testdecimal.rb create test/unit/testdecimal_test.rb create test/fixtures/testdecimals.yml exists db/migrate create db/migrate/003_create_testdecimals.rb bash mac maco /pt/books/rails2_my_depot/depot 19 $ bash mac maco /pt/books/rails2_my_depot/depot 19 $ vi db/migrate/003_create_testdecimals.rb bash mac maco /pt/books/rails2_my_depot/depot 20 $ bash mac maco /pt/books/rails2_my_depot/depot 20 $ cat db/migrate/003_create_testdecimals.rb class CreateTestdecimals < ActiveRecord::Migration def self.up create_table :testdecimals do |t| t.column :dec1, :decimal end end def self.down drop_table :testdecimals end end bash mac maco /pt/books/rails2_my_depot/depot 21 $ bash mac maco /pt/books/rails2_my_depot/depot 21 $ bash mac maco /pt/books/rails2_my_depot/depot 21 $ bash mac maco /pt/books/rails2_my_depot/depot 21 $ bash mac maco /pt/books/rails2_my_depot/depot 21 $ bash mac maco /pt/books/rails2_my_depot/depot 21 $ rake db:migrate (in /pt/books/rails2_my_depot/depot) == CreateTestdecimals: migrating =============================================-- create_table(:testdecimals) NOTICE: CREATE TABLE will create implicit sequence "testdecimals_id_seq" for serial column "testdecimals.id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "testdecimals_pkey" for table "testdecimals" -> 0.2935s == CreateTestdecimals: migrated (0.2939s) ==================================== bash mac maco /pt/books/rails2_my_depot/depot 22 $ bash mac maco /pt/books/rails2_my_depot/depot 22 $ depot_development=# depot_development=# depot_development=# depot_development=# \d testdecimals \d testdecimals Table "public.testdecimals" Column | Type | Modifiers --------+---------+----------------------------------------------------------- id | integer | not null default nextval(''testdecimals_id_seq''::regclass) dec1 | numeric | Indexes: "testdecimals_pkey" PRIMARY KEY, btree (id) depot_development=# depot_development=# depot_development=# So, it looks like my problem is isolated to the situation where I want to add a column with data type of decimal to a table. The migration works okay if the decimal data type resides in a create_table() method. -Dan On 8/3/06, Dan Bikle <dan.bikle@gmail.com> wrote:> > People, > > I''m looking at the migrate example on p 74 of the rails2.pdf > > It''s a simple example of using a migration to add a column to > the products table. > > Here is a copy of the migration file named 002_add_price.rb > after I generated and then edited it: > > class AddPrice < ActiveRecord::Migration > def self.up > add_column :products, :price, :decimal, :precision => 8, :scale => 2, > :default => 0 > end > > def self.down > remove_column :products, :price > end > end > > > I see this error when I walk through the demo: > > > bash mac maco /pt/books/rails2_my_depot/depot 9 $ > bash mac maco /pt/books/rails2_my_depot/depot 9 $ rake db:migrate --trace > (in /pt/books/rails2_my_depot/depot) > ** Invoke db:migrate (first_time) > ** Invoke environment (first_time) > ** Execute environment > ** Execute db:migrate > == AddPrice: migrating > =======================================================> -- add_column(:products, :price, :decimal, {:precision=>8, :scale=>2, > :default=>0}) > rake aborted! > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occured while evaluating nil.[] > /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:259:in > `type_to_sql'' > /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/connection_adapters/postgresql_adapter.rb:310:in > `add_column'' > /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:272:in > `method_missing'' > /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:256:in > `say_with_time'' > /r/lib/ruby/1.8/benchmark.rb:293:in `measure'' > /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:256:in > `say_with_time'' > /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:270:in > `method_missing'' > ./db/migrate//002_add_price.rb:3:in `real_up'' > /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:210:in > `migrate'' > /r/lib/ruby/1.8/benchmark.rb:293:in `measure'' > /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:210:in > `migrate'' > /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:332:in > `migrate'' > /r/lib/ruby/gems/1.8/gems/activerecord- 1.14.3/lib/active_record/migration.rb:327:in > `migrate'' > /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:294:in > `up'' > /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:285:in > `migrate'' > /r/lib/ruby/gems/1.8/gems/rails-1.1.4/lib/tasks/databases.rake:4 > /r/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute'' > /r/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute'' > /r/lib/ruby/gems/1.8/gems/rake-0.7.1 /lib/rake.rb:357:in `invoke'' > /r/lib/ruby/1.8/thread.rb:135:in `synchronize'' > /r/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in `invoke'' > /r/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run'' > /r/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run'' > /r/lib/ruby/gems/1.8/gems/rake-0.7.1/bin/rake:7 > /r/bin/rake:18 > bash mac maco /pt/books/rails2_my_depot/depot 10 $ > bash mac maco /pt/books/rails2_my_depot/depot 10 $ > bash mac maco /pt/books/rails2_my_depot/depot 10 $ > > Info about my setup: > > bash mac maco /pt/books/rails2_my_depot/depot 12 $ > bash mac maco /pt/books/rails2_my_depot/depot 12 $ > bash mac maco /pt/books/rails2_my_depot/depot 12 $ uname -a > Darwin mac 8.7.0 Darwin Kernel Version 8.7.0: Fri May 26 15:20:53 PDT > 2006; root:xnu-792.6.76.obj~1/RELEASE_PPC Power Macintosh powerpc > bash mac maco /pt/books/rails2_my_depot/depot 13 $ > bash mac maco /pt/books/rails2_my_depot/depot 13 $ > bash mac maco /pt/books/rails2_my_depot/depot 13 $ > [ os x 10.4 ] > > > bash mac maco /pt/books/rails2_my_depot/depot 19 $ > bash mac maco /pt/books/rails2_my_depot/depot 19 $ > bash mac maco /pt/books/rails2_my_depot/depot 19 $ > bash mac maco /pt/books/rails2_my_depot/depot 19 $ psql depot_development > Welcome to psql 8.1.4, the PostgreSQL interactive terminal. > > > bash mac maco /pt/books/rails2_my_depot/depot 12 $ > bash mac maco /pt/books/rails2_my_depot/depot 12 $ > bash mac maco /pt/books/rails2_my_depot/depot 12 $ > bash mac maco /pt/books/rails2_my_depot/depot 12 $ > bash mac maco /pt/books/rails2_my_depot/depot 11 $ gem list --local > > *** LOCAL GEMS *** > > actionmailer (1.2.3) > Service layer for easy email delivery and testing. > > actionpack (1.12.3) > Web-flow and rendering framework putting the VC in MVC. > > actionwebservice (1.1.4) > Web service support for Action Pack. > > activerecord (1.14.3) > Implements the ActiveRecord pattern for ORM. > > activesupport (1.3.1) > Support and utility classes used by the Rails framework. > > postgres (0.7.1) > The extension library to access a PostgreSQL database from Ruby. > > rails (1.1.4) > Web-application framework with template engine, control-flow layer, > and ORM. > > rake (0.7.1) > Ruby based make-like utility. > > sources (0.0.1) > This package provides download sources for remote gem installation > bash mac maco /pt/books/rails2_my_depot/depot 12 $ > bash mac maco /pt/books/rails2_my_depot/depot 12 $ > bash mac maco /pt/books/rails2_my_depot/depot 12 $ > bash mac maco /pt/books/rails2_my_depot/depot 12 $ > > > Anyone have any clues on how I can get this to work? > > Thanks, > > -Dan > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060804/71f33b3c/attachment-0001.html
jeanpierre@gmail.com
2006-Aug-04 05:53 UTC
[Rails] Demo in rails2.pdf of add_price migration, PostgreSQL 8.1.4
On 8/3/06, Dan Bikle <dan.bikle@gmail.com> wrote:> Well, > > I ran a simple experiment where I tried adding a column with data type of > string rather than decimal and it worked well. > > Then, I ran another experiment where I tried creating a table with a column > with data type of decimal and it succeeded:is that migration (the latest revision of Agile Web...) using BigDecimal (as seen in edge rails)? regards, jean-pierre
Dan Bikle
2006-Aug-04 07:03 UTC
[Rails] Demo in rails2.pdf of add_price migration, PostgreSQL 8.1.4
Nope, I''m not using BigDecimal nor edge rails. I used gem to install rails on July 29 so right now my rails is at rails-1.1.4 -Dan On 8/3/06, jeanpierre@gmail.com <jeanpierre@gmail.com> wrote:> > On 8/3/06, Dan Bikle <dan.bikle@gmail.com> wrote: > > Well, > > > > I ran a simple experiment where I tried adding a column with data type > of > > string rather than decimal and it worked well. > > > > Then, I ran another experiment where I tried creating a table with a > column > > with data type of decimal and it succeeded: > > > is that migration (the latest revision of Agile Web...) using > BigDecimal (as seen in edge rails)? > > regards, > jean-pierre > _______________________________________________ > 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/20060804/337199d3/attachment.html
jeanpierre@gmail.com
2006-Aug-04 16:35 UTC
[Rails] Demo in rails2.pdf of add_price migration, PostgreSQL 8.1.4
On 8/4/06, Dan Bikle <dan.bikle@gmail.com> wrote:> Nope, > > I''m not using BigDecimal nor edge rails. > > I used gem to install rails on July 29 so right now my rails is at > rails-1.1.4precisely, i thought that the latest push of Agile Web... used the BigDecimal support found in edge rails? cheers, jean-pierre
Asa Hopkins
2006-Aug-04 17:42 UTC
[Rails] Re: Demo in rails2.pdf of add_price migration, PostgreSQL 8.
Dan, My impression from previous posts and Dave Thomas''s comments when the new version fo the beta book came out (haven''t tried it all myself) is that the :decimal column in migrations, linked to the ruby BigDecimal class, is a feature currently in Edge Rails, but not in Rails 1.1.4. So, you can either wait for 1.2 or whenever it shows up in a release, or freeze edge rails in your app. Asa Dan Bikle wrote:> People, > > I''m looking at the migrate example on p 74 of the rails2.pdf > > It''s a simple example of using a migration to add a column to > the products table. > > Here is a copy of the migration file named 002_add_price.rb > after I generated and then edited it: > > class AddPrice < ActiveRecord::Migration > def self.up > add_column :products, :price, :decimal, :precision => 8, :scale => > 2, > :default => 0 > end > > def self.down > remove_column :products, :price > end > end > > > I see this error when I walk through the demo: > > > bash mac maco /pt/books/rails2_my_depot/depot 9 $ > bash mac maco /pt/books/rails2_my_depot/depot 9 $ rake db:migrate > --trace > (in /pt/books/rails2_my_depot/depot) > ** Invoke db:migrate (first_time) > ** Invoke environment (first_time) > ** Execute environment > ** Execute db:migrate > == AddPrice: migrating > =======================================================> -- add_column(:products, :price, :decimal, {:precision=>8, :scale=>2, > :default=>0}) > rake aborted! > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occured while evaluating nil.[] > /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:259:in > `type_to_sql'' > /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/connection_adapters/postgresql_adapter.rb:310:in > `add_column''> --snip--> bash mac maco /pt/books/rails2_my_depot/depot 12 $ > bash mac maco /pt/books/rails2_my_depot/depot 12 $ > bash mac maco /pt/books/rails2_my_depot/depot 11 $ gem list --local > > *** LOCAL GEMS *** > > > rails (1.1.4) > Web-application framework with template engine, control-flow layer, > and ORM. >-- Posted via http://www.ruby-forum.com/.
Dave Thomas
2006-Aug-05 05:17 UTC
[Rails] Demo in rails2.pdf of add_price migration, PostgreSQL 8.1.4
On Aug 4, 2006, at 2:03 AM, Dan Bikle wrote:> I''m not using BigDecimal nor edge rails. > > I used gem to install rails on July 29 so right now my rails is at > rails-1.1.4You need to be running edge Rails in order to run these examples--the book is written in the anticipation of 1.2, which support BigDecimal for decimal columns. It''s a significant enough change that I wanted to roll it in now. Regards Dave Thomas -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060805/56e50cc3/attachment.html
I''m in the process of going through the beta version of AWDWR. I came to the example which uses ''BigDecimal'' and skipped ahead to install Edge Rails. I don''t know if this is a question for Dave Thomas or one of the Rails developers. On page 236 of the beta version of the .pdf: After successfully installing Subversion v. 1.1.4 (''make check'' reports all tests successful), when I attempt to run the command: svn propset svn:externals \ "rails http://dev.rubyonrails.org/svn/rails/trunk" vendor (yes, on the same line, without the backslash) I get the following response: "svn: ''vendor'' is not a working copy" I don''t know what I should replace the ''vendor'' tag with. Please let me know if there is a simple fix or what the tag that should replace the ''vendor'' tag should be. Thanks for the great book and the early look. TIA for any and all responses. -- Steve Email: s dot d at comcast dot net
this error can occur when your project is not in svn. either make it svn, check it out and try again or just svn co http://dev.rubyonrails.org/svn/rails/trunk vendor/rails in your app directory. this checks out a working copy (if i remind the syntax corectly, if not, see the svn docs and let me know) 2006/8/6, Steve Downie <rails@maintenancemode.com>:> > I''m in the process of going through the beta version of AWDWR. I came to > the example which uses ''BigDecimal'' and skipped ahead to install Edge > Rails. > I don''t know if this is a question for Dave Thomas or one of the Rails > developers. > > On page 236 of the beta version of the .pdf: > > After successfully installing Subversion v. 1.1.4 (''make check'' reports > all tests successful), when I attempt to run the command: > > svn propset svn:externals \ > "rails http://dev.rubyonrails.org/svn/rails/trunk" vendor > > (yes, on the same line, without the backslash) > I get the following response: > > "svn: ''vendor'' is not a working copy" > > I don''t know what I should replace the ''vendor'' tag with. Please let me > know if there is a simple fix or what the tag that should replace the > ''vendor'' tag should be. > Thanks for the great book and the early look. > > TIA for any and all responses. > > -- Steve > Email: s dot d at comcast dot net > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Michael Siebert <info@siebert-wd.de> www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060806/162b7935/attachment.html