This project is archived and is in readonly mode.

#5830 ✓stale
kapouer

mysql adapter should create table with default charset

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

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.

Comments and changes to this ticket

  • Scott M. Likens

    Scott M. Likens October 17th, 2010 @ 07:33 PM

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

    http://github.com/brianmario/mysql2

  • kapouer

    kapouer October 17th, 2010 @ 07:38 PM

    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.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:29 PM

    • 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.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:29 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages