syntax error, unexpected ‘\n’, expecting tCOLON2 or ‘[’ or ‘.’ in rails migrations, sqlite3

Are you getting the following error:

1 syntax error, unexpected '\n', expecting tCOLON2 or '[' or '.'
      

I was too, and it was a stupid mistake.

I had my migrations’ lines mixed up and containing a comma where there should not have been one.

Incorrect format:

 1 class CreatePages < ActiveRecord::Migration
       2   def self.up
       3      create_table :pages do |t|
       4         t.parent_id, :integer, :default => 0, :null => false
       5         t.string :title
       6         t.text :body
       7         t.position, :integer
       8         t.boolean :hidden, :default => false
       9         t.main_nav, :boolean
      10         t.top_nav, :boolean
      11         t.footer_nav, :boolean
      12         t.timestamps
      13       end
      14   end
      15 
      16   def self.down
      17     drop_table :pages
      18   end
      19 end
      

 1 class CreatePages < ActiveRecord::Migration
2 def self.up
3 create_table :pages do |t|
4 t.parent_id, :integer, :default => 0, :null => false
5 t.string :title
6 t.text :body
7 t.position, :integer
8 t.boolean :hidden, :default => false
9 t.main_nav, :boolean
10 t.top_nav, :boolean
11 t.footer_nav, :boolean
12 t.timestamps
13 end
14 end
15
16 def self.down
17 drop_table :pages
18 end
19 end

Correct format:

 1 class CreatePages < ActiveRecord::Migration
       2   def self.up
       3      create_table :pages do |t|
       4         t.integer :parent_id, :default => 0, :null => false
       5         t.string :title
       6         t.text :body
       7         t.integer :position
       8         t.boolean :hidden, :default => false
       9         t.boolean :main_nav
      10         t.boolean :top_nav
      11         t.boolean :footer_nav
      12         t.timestamps
      13       end
      14   end
      15 
      16   def self.down
      17     drop_table :pages
      18   end
      19 end
      

 1 class CreatePages < ActiveRecord::Migration
2 def self.up
3 create_table :pages do |t|
4 t.integer :parent_id, :default => 0, :null => false
5 t.string :title
6 t.text :body
7 t.integer :position
8 t.boolean :hidden, :default => false
9 t.boolean :main_nav
10 t.boolean :top_nav
11 t.boolean :footer_nav
12 t.timestamps
13 end
14 end
15
16 def self.down
17 drop_table :pages
18 end
19 end

Picture of Scott Motte

delicious facebook rss twitter

Spitfire Sky | github | archives | resume