In one of my migration files I have the following: ========== def self.up User.create :name => ''John Kopanas'', :email => ''john@kopanas.com'', :password => ''test'' end ========== When I run it I get the following error: ==========undefined method `create'' for #<ActiveRecord::ConnectionAdapters::MysqlAdapter:0x2345c1c> ========== When I copy the line and paste it in console it works perfectly. Even using the longer method of ==========user = User.new user.name user.save ========== Does not work in the migration. Tells me method name does not exist. It exists. Anyone have any insight about this. Problem has been driving me crazy for the last 30 minutes. :-) Your Friend John Kopanas
Try putting class User < ActiveRecord::Base; end; In your migration. I forget if it needs to go inside or outside the migration class (I''d think inside), so if one doesn''t work, give the other one a shot. Pat On 3/21/06, John Kopanas <john@protoseinc.com> wrote:> In one of my migration files I have the following: > > ==========> def self.up > User.create :name => ''John Kopanas'', :email => > ''john@kopanas.com'', :password => ''test'' > end > ==========> > When I run it I get the following error: > > ==========> undefined method `create'' for > #<ActiveRecord::ConnectionAdapters::MysqlAdapter:0x2345c1c> > ==========> > When I copy the line and paste it in console it works perfectly. > Even using the longer method of > > ==========> user = User.new > user.name > user.save > ==========> > Does not work in the migration. Tells me method name does not > exist. It exists. > > Anyone have any insight about this. Problem has been driving me > crazy for the last 30 minutes. :-) > > Your Friend > > John Kopanas > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
I even started getting some funny errors like ============superclass mismatch for class User ============ I ended up deleting the user model and migration files and started again and it worked perfectly. Thanks On 21-Mar-06, at 1:07 PM, Pat Maddox wrote:> Try putting > > class User < ActiveRecord::Base; end; > > In your migration. I forget if it needs to go inside or outside the > migration class (I''d think inside), so if one doesn''t work, give the > other one a shot. > > Pat > > > > On 3/21/06, John Kopanas <john@protoseinc.com> wrote: >> In one of my migration files I have the following: >> >> ==========>> def self.up >> User.create :name => ''John Kopanas'', :email => >> ''john@kopanas.com'', :password => ''test'' >> end >> ==========>> >> When I run it I get the following error: >> >> ==========>> undefined method `create'' for >> #<ActiveRecord::ConnectionAdapters::MysqlAdapter:0x2345c1c> >> ==========>> >> When I copy the line and paste it in console it works perfectly. >> Even using the longer method of >> >> ==========>> user = User.new >> user.name >> user.save >> ==========>> >> Does not work in the migration. Tells me method name does not >> exist. It exists. >> >> Anyone have any insight about this. Problem has been driving me >> crazy for the last 30 minutes. :-) >> >> Your Friend >> >> John Kopanas >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/railsJohn Kopanas