GeekedOut
GeekedOut

Reputation: 17185

Migration syntax errors when adding utf-8 and InnoDB instructions in Rails

I am trying to create this rails migration

class CreateFormats < ActiveRecord::Migration
  def self.up
    create_table (:formats , :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8' ) do |t|
      t.name
      t.description 
      t.company

      t.timestamps
    end
  end

  def self.down
    drop_table :formats
  end
end

And I get errors during execution that look like this:

syntax error, unexpected ',', expecting ')' create_table (:formats , :options => 'ENGINE=InnoDB D... ^ syntax error, unexpected ')', expecting keyword_end ...=InnoDB DEFAULT CHARSET=utf8' ) do |t| ... ^

syntax error, unexpected keyword_end, expecting $end

Any idea why this happened? I can't find any problems with my syntax..most likely because I am new to Rails :)

Upvotes: 0

Views: 704

Answers (1)

Pan Thomakos
Pan Thomakos

Reputation: 34350

Your syntax is incorrect:

create_table (:formats , :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8' ) do |t|

should be

create_table(:formats , :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8' ) do |t|

i.e: without the space. Otherwise you are simply grouping :formats with :options => ... as the first argument to the function.

You probably also need to change

t.name
t.description 
t.company

to something like

t.string :name
t.string :description 
t.string :company

Upvotes: 2

Related Questions