开发者

Rails db:migrate fails with SQL error

开发者 https://www.devze.com 2023-04-07 00:54 出处:网络
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

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
0

精彩评论

暂无评论...
验证码 换一张
取 消