(Bear in mind, though, that by specifying DBMS-specific table creation
syntax, you lose portability between DBMSs.)
>> ActiveRecord::Schema.define do
?> create_table :test do end
>> end
-- create_table(:test)
SQL (0.028168) CREATE TABLE `test` (`id` int(11) DEFAULT NULL
auto_increment PRIMARY KEY) ENGINE=InnoDB
-> 0.1264s
=> nil
>> ActiveRecord::Schema.define do
?> create_table :test2, :options =>
'ENGINE=InnoDB DEFAULT CHARSET=utf8' do end
>> end
-- create_table(:test2, {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8"})
SQL (0.028386) CREATE TABLE `test2` (`id` int(11) DEFAULT NULL
auto_increment PRIMARY KEY) ENGINE=InnoDB
DEFAULT CHARSET=utf8
-> 0.0287s
=> nil
However, none of these methods will handle preexisting databases. Chances are, if
you have created databases and tables without specifying CHARACTER SET utf8, the
tables are treating the data as Latin1. If the data is actually Latin1 (and you are now
converting the entire application to Unicode at once), the conversion is simple,
though it must be done once for each table:
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8;
If your only need is straight data conversion, this will work. If you are using
ActiveRecord migrations, Graeme Mathieson has written a migration that will perform
this conversion for every table in your database. It is available from http://woss.name/
2006/10/25/migrating-your-rails-application-to-unicode/.
Pages:
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386