且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Rails中使用主键创建表和问题

更新时间:2023-11-24 12:56:10

我之前也遇到过同样的问题,我根据这里解决了 https://github.com/rails/rails/pull/13247#issuecomment-32425844

I had a same problem before, and I solved according to here https://github.com/rails/rails/pull/13247#issuecomment-32425844

使用Rails 2.3.5,MySQL 5.7.9版本和mysql gem需要具备 此位用作初始化程序 config/initializers/abstract_mysql_adapter.rb:

With Rails 2.3.5, MySQL version 5.7.9 and mysql gem you need to have this bit as an initializer in config/initializers/abstract_mysql_adapter.rb:

class ActiveRecord::ConnectionAdapters::MysqlAdapter
  NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY"
end

对于mysql2,它应该是config/initializers/abstract_mysql2_adapter.rb:

For mysql2, it should be config/initializers/abstract_mysql2_adapter.rb:

class ActiveRecord::ConnectionAdapters::Mysql2Adapter
  NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY"
end