1

rake db:migrate is failing on my production server, the error is:

Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'String' at line 1: 'ALTER TABLE looks' ADD 'code' String

My migration code is:

class AddCodeToLook < ActiveRecord::Migration
  def self.up
    add_column :looks, :code, :String #failing line
  end

  def self.down
    remove_column :looks, :code
  end
end
0

3 Answers 3

3

Try :string and not :String

Sign up to request clarification or add additional context in comments.

2 Comments

Oh, man I didn't even noticed, strangely it worked on sqlite. Thank you so much, I'm really grateful!
Sometimes you can bang your head against these tiny little mistakes for ages and you either figure it out eventually, or someone else spots it instantly :P
0

Not sure if that's just a typo, but :String should be :string in your add_column line.

When you add a column like this, you can use the built-in rails generator to handle the grunt work:

rails g migration AddCodeToLook code:string

Comments

0

Per this official Rails documentation, it looks like the issue is that you're not using the right casing for the data type. You should be using :string.

class AddCodeToLook < ActiveRecord::Migration
  def self.up
    add_column :looks, :code, :string
  end

  def self.down
    remove_column :looks, :code
  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.