0

I am using sqlite3 as development db. I used this code to migrate db

rake db:migrate

Also tried this rails db:migrate However I got this error

*SyntaxError: /Users/kangkanlahkar/Desktop/Codes/Ruby/practice/db/migrate/20170721152949_create_users.rb:4: syntax error, unexpected '\n', expecting &. or :: or '[' or '.'
/Users/kangkanlahkar/Desktop/Codes/Ruby/practice/db/migrate/20170721152949_create_users.rb:5: syntax error, unexpected '\n', expecting &. or :: or '[' or '.'*

Any idea how to fix it. I am using mac.

But the command rails db:migrate:status works fine

Content of 20170721152949_create_users.rb file

class CreateUsers < ActiveRecord::Migration[5.1]
  def change
    create_table :users do |t|
      t.string, :name
      t.string, :email
      t.integer :phone
      t.timestamps
    end
  end
end
2
  • the problem from this migration file db\migrate\20170721152949_create_users.rb, can you upload the content Commented Jul 21, 2017 at 16:29
  • I have added the content of the file Commented Jul 21, 2017 at 16:34

3 Answers 3

1

You just need to remove extra commas after t.string that's causing the syntax error. Try the following:

class CreateUsers < ActiveRecord::Migration[5.1]
  def change
    create_table :users do |t|
      t.string :name
      t.string :email
      t.integer :phone
      t.timestamps
    end
  end
end
Sign up to request clarification or add additional context in comments.

Comments

1

syntax error, unexpected '\n', expecting &. or :: or '[' or '.'

You have to remove the commas(,) after t.string

class CreateUsers < ActiveRecord::Migration[5.1]
  def change
    create_table :users do |t|
      t.string :name
      t.string :email
      t.integer :phone
      t.timestamps
    end
  end
end

Comments

1

Remove the commas after t.string:

class CreateUsers < ActiveRecord::Migration[5.1]
  def change
    create_table :users do |t|
      t.string :name
      t.string :email
      t.integer :phone
      t.timestamps
    end
  end
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.