0

Have a little issue going on, not too sure what I've done but I just created a rails application followed by these commands.

I ran:

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

in my terminal followed by:

rake db:migrate

Next I get an error that reads:

    == 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)

Migration file:

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
illywilly
  • 323
  • 1
  • 5
  • 18
  • 1
    The scaffold syntax doesnt look right. You probably need types for neighborhood and external_url – shishirmk Jan 08 '15 at 01:41
  • show us the migration file – Anthony Jan 08 '15 at 02:15
  • Added the migration file @Anthony – illywilly Jan 08 '15 at 02:34
  • Okay so this is weird because I tried testing this on another app and it seems every time I run rake db:migrate I get the error "rake aborted!..." – illywilly Jan 08 '15 at 02:45
  • 1
    your scaffold works just fine for me. Your schema doesn't already include a posts table right? – Anthony Jan 08 '15 at 03:03
  • Scaffold command also works fine for me when running `db:migrate`. I second the need for checking whether there is already a posts table. I also question why you are manually creating a `timestamp` column as that could cause a lot of confusion for someone trying to understand your Post model. – Rob Wise Jan 08 '15 at 03:43
  • No it doesn't already include the posts table. I tried dropping tables in the console, recreating then rake db:reset and still nothing. – illywilly Jan 08 '15 at 03:55

2 Answers2

0

This is what the command should be

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

You should be mentioning the data types for all the fields .

Caffeine Coder
  • 1,869
  • 1
  • 17
  • 35
0

The problem was in my gem file, my rails version was rails 4.2 beta 2. I found the solution here:

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

I had to add the gem arel and run bundle update arel followed by bundle install.

Community
  • 1
  • 1
illywilly
  • 323
  • 1
  • 5
  • 18