11

I am trying to migrate subject_id and course_id to the users table by typing:

rails generate migration add_course_id_and_subject_id_to_users course_id:integer, subject_id:integer

However, it results in the error:

_add_course_id_and_subject_id_to_users.rb:4: syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '('

Not sure why this is happening.

Gumbo
  • 643,351
  • 109
  • 780
  • 844
achilles77
  • 325
  • 2
  • 3
  • 11

1 Answers1

18

This is shell syntax, not Ruby syntax, so you need to drop the comma between you attribute defs:

rails generate migration add_course_id_and_subject_id_to_users course_id:integer subject_id:integer

With the comma, you're trying to add two fields, "course_id:integer," (comma!) and "subject_id:integer" with the types "integer," (comma!) and "integer", respectively.

Somewhere along the road, the generated Ruby code will have that syntax error and raise the exception.

awendt
  • 13,195
  • 5
  • 48
  • 66