Last active
February 10, 2016 23:19
-
-
Save richardsondx/5a007a3a1ab979096b92 to your computer and use it in GitHub Desktop.
Fix for ActiveRecord::JDBCError: All parts of a PRIMARY KEY must be NOT NULL;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# class ActiveRecord::ConnectionAdapters::Mysql2Adapter | |
module ActiveRecord | |
module ConnectionAdapters | |
class AbstractMysqlAdapter < AbstractAdapter | |
# https://github.com/rails/rails/blob/a4b55827721a5967299f3c1531afb3d6d81e4ac0/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb#L113-L126 | |
NATIVE_DATABASE_TYPES = { | |
:primary_key => "int(11) auto_increment PRIMARY KEY", | |
:string => { :name => "varchar", :limit => 255 }, | |
:text => { :name => "text" }, | |
:integer => { :name => "int", :limit => 4 }, | |
:float => { :name => "float" }, | |
:decimal => { :name => "decimal" }, | |
:datetime => { :name => "datetime" }, | |
:timestamp => { :name => "datetime" }, | |
:time => { :name => "time" }, | |
:date => { :name => "date" }, | |
:binary => { :name => "blob" }, | |
:boolean => { :name => "tinyint", :limit => 1 } | |
} | |
def native_database_types | |
NATIVE_DATABASE_TYPES | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example 2 | |
# https://github.com/rails/rails/blob/a4b55827721a5967299f3c1531afb3d6d81e4ac0/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb#L113-L126 | |
class ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter | |
NATIVE_DATABASE_TYPES = { | |
:primary_key => "int(11) auto_increment PRIMARY KEY", | |
:string => { :name => "varchar", :limit => 255 }, | |
:text => { :name => "text" }, | |
:integer => { :name => "int", :limit => 4 }, | |
:float => { :name => "float" }, | |
:decimal => { :name => "decimal" }, | |
:datetime => { :name => "datetime" }, | |
:timestamp => { :name => "datetime" }, | |
:time => { :name => "time" }, | |
:date => { :name => "date" }, | |
:binary => { :name => "blob" }, | |
:boolean => { :name => "tinyint", :limit => 1 } | |
} | |
def native_database_types | |
NATIVE_DATABASE_TYPES | |
end | |
end | |
class ActiveRecord::ConnectionAdapters::Mysql2Adapter | |
NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY" | |
end |
smathy
commented
Feb 10, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment