新手问题 [已解决] 运行 rake db:migrate 报异常

LinuxGit · 2014年12月15日 · 最后由 linuxgit 回复于 2014年12月16日 · 3970 次阅读
rails g model User name:string email:string

只要一运行 rake db:migrate 就报以下错误,新建其他 Model 也是,求助。

 > bundle exec rake db:migrate
== 20141215151923 CreatePosts: migrating ======================================
-- create_table(:posts)
   -> 0.0048s
== 20141215151923 CreatePosts: migrated (0.0049s) =============================

rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

wrong number of arguments (1 for 0)/home/diglike/.rvm/gems/ruby-2.1.4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `initialize'
/home/diglike/.rvm/gems/ruby-2.1.4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `new'
/home/diglike/.rvm/gems/ruby-2.1.4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `substitute_at'
/home/diglike/.rvm/gems/ruby-2.1.4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:97:in `block in substitute_values'
/home/diglike/.rvm/gems/ruby-2.1.4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96:in `each'
/home/diglike/.rvm/gems/ruby-2.1.4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96:in `each_with_index'
/home/diglike/.rvm/gems/ruby-2.1.4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96:in `substitute_values'
/home/diglike/.rvm/gems/ruby-2.1.4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:56:in `insert'

我的 Gemfile 如下:

source 'https://rubygems.org'

gem 'rails', '4.2.0.beta4'
gem 'sqlite3',    '1.3.10'
gem 'sass-rails', '5.0.0.beta1'
gem 'bootstrap-sass', '3.3.1.0'
gem 'uglifier', '2.6.0'
gem 'coffee-rails', '4.1.0'

gem 'jquery-rails', '4.0.0.beta2'
gem 'turbolinks', '2.5.3'
gem 'jbuilder', '2.2.5'
gem 'sdoc', '0.4.0', group: :doc

group :development, :test do
  gem 'byebug', '3.5.1'
  gem 'web-console', '2.0.0.beta4'
  gem 'spring', '1.2.0'
end

group :test do
  gem 'minitest-reporters', '1.0.8'
  gem 'mini_backtrace', '0.1.3'
  gem 'guard-minitest', '2.3.2'
end

/app/db/migrate/*,最后一个文件内容请贴出。

@linuxgit 这个不是说了吗 wrong number of arguments 。需要看看你的需要 migrate 的文件是否写错了呀!

db/migrate 目录 posts 后面的文件是否正确

在 Gemfile 中把 Rails 的版本号改为 4.2.0.rc1

#4 楼 @jyootai @cherest @floger @yutian 谢谢大家的热心回复,我的 migrate 文件生成后没有修改过。按 jyootai 的方法,我升级 rails 到 4.2.0.rc3 就正常了。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册