使用.new从rails控制台出错

时间:2023-01-16 09:43:50

Here is the error message in rails production console. User is a model and the error is created by "a = User.new".

以下是rails生产控制台中的错误消息。用户是模型,错误由“a = User.new”创建。

D:\rails_proj\emclab-failed>rails c production
Loading production environment (Rails 3.1.0)
irb(main):001:0> a = User.new
  ←[1m←[36m (0.0ms)←[0m  ←[1mSHOW TABLES←[0m
  ←[1m←[35m (10.0ms)←[0m  describe `users`
SyntaxError: C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/read.rb:91: syntax error, unexpected keyword_end
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/read.rb:93: syntax error, unexpected $end, expecting keyword_end
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/read.rb:83:in `module_eval'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/read.rb:83:in `define_read_method'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/read.rb:42:in `define_method_attribute'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/time_zone_conversion.rb:35:in `define_method_attribute'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:291:in `block in define_attribute_method'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:286:in `each'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:286:in `define_attribute_method'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:282:in `block in define_attribute_methods'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:282:in `each'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:282:in `define_attribute_methods'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods.rb:14:in `define_attribute_methods'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods.rb:65:in `respond_to?'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/read.rb:103:in `read_attribute'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:1774:in `attribute_for_inspect'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:1891:in `block in inspect'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:1889:in `collect'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:1889:in `inspect'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:45:in `start'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:8:in `start'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:40:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'irb(main):002:0>

However the same command in development generates a new instance without any error. The difference is that there is no data in production database. It is sqlite3 for development and mysql 5.1.54 for production.

但是,开发中的相同命令会生成一个没有任何错误的新实例。不同之处在于生产数据库中没有数据。它是用于开发的sqlite3和用于生产的mysql 5.1.54。

Loading development environment (Rails 3.1.0)
irb(main):001:0> a = User.new
=> #<User id: nil, name: nil, email: nil, encrypted_password: nil, salt: nil, status: "active", created_at: nil, updated_at: nil, user_type: nil>

Any thoughts? thanks.

有什么想法吗?谢谢。

1 个解决方案

#1


1  

What gem are you using for mysql? According to this issue you may just need to run bundle update mysql2 if you're using the mysql2 gem.

你用什么宝石用于mysql?根据这个问题,如果你使用的是mysql2 gem,你可能只需要运行bundle update mysql2。

#1


1  

What gem are you using for mysql? According to this issue you may just need to run bundle update mysql2 if you're using the mysql2 gem.

你用什么宝石用于mysql?根据这个问题,如果你使用的是mysql2 gem,你可能只需要运行bundle update mysql2。