PRIMARY KEY issue with creating tables in Rails using rake db:migrate command with mysql

后端 未结 5 1220
余生分开走
余生分开走 2020-12-31 00:38

My version of rails is 4.0.0, my version of mysql is Ver 14.14 Distrib 5.7.9, for Win64 (x86_64). I am operating of an older version of rails as I was getting some clashes w

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-31 00:58

    Did not have luck with the solutions above (My env: Rails 3.0.20, MySQL 5.7.13, Ruby 1.9.3p551). Was able to get around it by overwriting the ActiveRecord::ConnectionAdapters::ColumnDefinition class. See below:

    class ActiveRecord::ConnectionAdapters::ColumnDefinition
      def sql_type
        type.to_sym == :primary_key ? 'int(11) auto_increment PRIMARY KEY' : base.type_to_sql(type.to_sym, limit, precision, scale) rescue type
      end 
    end
    

    Stored this in config/initializers/column_definition.rb

提交回复
热议问题