我正在学习 laravel,我被困在一个简单的过程中。我希望将表生成为 UTF-8,但 varchar 和文本字段就像 latin-1。
指南中的架构部分根本没有帮助。我找到了这个 GitHub 条目 ,但它也不起作用(向我抛出错误)。
我有这样的架构:
<?php
class Create_Authors_Table {
/**
* Make changes to the database.
*
* @return void
*/
public function up()
{
Schema::create('authors',function($table){
//$table->charset('utf8'); //does not work
//$table->collate('utf8_general_ci'); //does not work
$table->increments('id');
$table->string('name')->charset('utf8'); //adding ->collate('utf8_general_ci') does not work
$table->text('bio')->charset('utf8');
$table->timestamps();
});
}
/**
* Revert the changes to the database.
*
* @return void
*/
public function down()
{
Schema::drop('authors');
}
}
这是 SQL 输出:
CREATE TABLE IF NOT EXISTS `authors` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL,
`bio` text NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
但这就是我需要的:
CREATE TABLE IF NOT EXISTS `authors` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL,
`bio` text NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
我什至把collation
钥匙放在我的 application/config/database.php
'mysql' => array(
'driver' => 'mysql',
'host' => '',
'database' => '',
'username' => '',
'password' => '',
'charset' => 'utf8',
'collation'=> 'utf8_unicode_ci', //this line was not there out of the box, googling provided me this
'prefix' => '',
),
我错过了什么,我该如何解决?
谢谢,