Question

I'm new to learning Ruby on Rails and when I run "rake db:migrate" in the command line I receive the following error:

rake aborted! SyntaxError: >/Users/user_name/Sites/simple_cms/db/migrate/20140423221836_alter_users.rb:15: syntax >error, unexpected ':', expecting ')' ...dmin_users", "email", :string :default => "", :null => false) ... ^

Tasks: TOP => db:migrate (See full trace by running task with --trace)**

Here is my code:

class AlterUsers < ActiveRecord::Migration

  def up
    rename_table("users", "admin_users")
    add_column("admin_users", "username", :string, :limit => 25, :after => "email")
    change_column("admin_users", "email", :string, :limit => 100)
    rename_column("admin_users", "password", "hashed_password")
    puts "*** Adding an index is next ***"
    add_index("admin_users", "username")
  end

  def down
    remove_index("admin_users", "username")
    rename_column("admin_users", "hashed_password", "password")
    change_column("admin_users", "email", :string :default => "", :null => false)
    remove_column("admin_users", "username")
    rename_table("admin_users", "users")
  end

end

I keep checking and rechecking my code but can't find the solution... Can someone with better eyes than me take a look? Thanks!

Was it helpful?

Solution

On 3rd line of down method, you missed a comma

change_column("admin_users", "email", :string :default => "", :null => false)

                                             ^ 
                                           ## missing comma

which is why you are getting error as unexpected ':', expecting ')' ...dmin_users", "email", :string :default => "", :null => false)

Simply, add a comma between :string and :default and run rake db:migrate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top