Ruby on Rails:rake db:运行scaffold后迁移错误

时间:2015-01-08 01:32:05

标签: ruby-on-rails ruby database

有一个小问题,不太确定我做了什么,但我刚刚创建了一个rails应用程序,然后是这些命令。

我跑了:

rails generate scaffold Post heading body:text price:decimal neighborhood external_url timestamp

在我的终端中,然后是:

rake db:migrate

接下来我收到一条错误:

    == 20150108012341 CreatePosts: migrating ======================================
    -- create_table(:posts)
       -> 0.0021s
    == 20150108012341 CreatePosts: migrated (0.0022s) =============================

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

    wrong number of arguments (1 for 0)/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.2.0.beta2/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `initialize'
    /Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-
...
4.2.0.beta2/lib/active_record/tasks/database_tasks.rb:135:in `migrate'
    /Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.2.0.beta2/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
    /Users/taimurknaziri/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
    /Users/taimurknaziri/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'
    Tasks: TOP => db:migrate
    (See full trace by running task with --trace)

迁移文件:

class CreatePosts < ActiveRecord::Migration
  def change
    create_table :posts do |t|
      t.string :heading
      t.text :body
      t.decimal :price
      t.string :neighborhood
      t.string :external_url
      t.string :timestamp

      t.timestamps null: false
    end
  end
end

2 个答案:

答案 0 :(得分:0)

这就是命令应该是

rails generate scaffold Post heading:string body:text price:decimal neighbourhood:string  externalurl:string timestamp:string

您应该提到所有字段的数据类型。

答案 1 :(得分:0)

问题出在我的gem文件中,我的rails版本是rails 4.2 beta 2.我在这里找到了解决方案:

Can't migrate database after scaffold. Section 2.2 Ruby on Rails Tutorial Michael Hartl

我必须添加gem arel并运行bundle update arel,然后再进行捆绑安装。