Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

mysql adapter should create table with default charset

#5830

mysql allows this :
CREATE TABLE DEFAULT CHARSET=utf8

But a pristine install of mysql does not create utf8 databases by default,
and it's a common source of error. (postgres and sqlite3 do use utf8 on most
up-to-date installs).
More annoying, many clients do not have the permissions to create the database,
and since it's Latin1 by default, they end up with ??? and complain.
Therefore this little patch would be great :

require 'active_record/connection_adapters/abstract_adapter'
module ActiveRecord
  module ConnectionAdapters
    class MysqlAdapter < AbstractAdapter
      def create_table(table_name, options = {}) #:nodoc:
        encoding = @config[:encoding]
        if encoding
          options = options.reverse_merge(:options => "DEFAULT CHARSET=#{encoding}")
        end
        super(table_name, options.reverse_merge(:options => "ENGINE=InnoDB"))
      end
    end
  end
end

However, i'm not sure the encoding strings allowed by activerecord match the ones of mysql.

Reported by kapouer · October 17th, 2010 @ 07:00 PM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Scott M. Likens
    Scott M. Likens

    Any problem with the mysql2 adapter which defaults to utf8 by default unless specified?

    http://github.com/brianmario/mysql2

    October 17th, 2010 @ 07:33 PM

  2. kapouer
    kapouer

    The mysql2 adapter is creating database with the right encoding,
    here i'm talking about creating table with the right encoding : it allows
    the use of utf8 tables within a database that has been created with the
    default server character set, which unfortunately isn't UTF8 on pristine mysql 5 installs.

    October 17th, 2010 @ 07:38 PM

  3. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:29 PM

  4. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:29 PM