rake db:migrate is failing 开发者_如何学Con 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
Try :string
and not :String
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
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
精彩评论