Laravel 3模式表列排序规则 [英] Laravel 3 Schema Table Column Collation
问题描述
我正在学习laravel,而且我坚持一个简单的过程.我希望将表生成为UTF-8,但varchar和文本字段类似于latin-1.
指南中的架构部分根本没有帮助.我找到了此GitHub条目,但它都不起作用(抛出错误).>
我有一个这样的架构:
<?php类Create_Authors_Table {/***对数据库进行更改.** @返回无效*/公共功能up(){Schema :: create('authors',function($ table){//$ table-> charset('utf8');//不起作用//$ table-> collate('utf8_general_ci');//不起作用$ table-> increments('id');$ table-> string('name')-> charset('utf8');//添加-> collate('utf8_general_ci')不起作用$ table-> text('bio')-> charset('utf8');$ table-> timestamps();});}/***将更改还原到数据库.** @返回无效*/公共功能down(){Schema :: drop('authors');}}
这是SQL输出:
如果不存在'authors',则创建表(`id` int(10)unsigned NOT NULL AUTO_INCREMENT,`name` varchar(200)NOT NULL,`bio`文字NOT NULL,"created_at"日期时间NOT NULL,`updated_at`日期时间NOT NULL,主键(`id`))ENGINE = InnoDB DEFAULT CHARSET = latin1 AUTO_INCREMENT = 1;
但这就是我所需要的:
如果不存在'authors',则创建表(`id` int(10)unsigned NOT NULL AUTO_INCREMENT,`name` varchar(200)NOT NULL,`bio`文字NOT NULL,"created_at"日期时间NOT NULL,`updated_at`日期时间NOT NULL,主键(`id`))ENGINE = InnoDB默认字符集utf8 COLLATE utf8_general_ci;
我什至将 collation
密钥放入我的application/config/database.php
'mysql'=>大批('驱动程序'=>'mysql','主机'=>'','数据库'=>'','用户名'=>'','password'=>'','字符集'=>'utf8','collation'=>'utf8_unicode_ci',//此行不是开箱即用的,谷歌搜索为我提供了此功能'前缀'=>'',),
我缺少什么,该如何解决?
谢谢
只需使用Linux Mint 13 Mate(基于Ubuntu 12.04 LTS)(使用mysql 5.5(5.5.29))解决了此问题
我在/etc/mysqld/my.cnf中添加了这些行
[客户端]默认字符集= utf8[mysqld]init_connect ='SET collation_connection = utf8_unicode_ci'字符集服务器= utf8整理服务器= utf8_unicode_ci
这样,SQL查询就可以在shell上正常工作,但是在laravel或phpmyadmin等上却无法正常工作.所以我这样做了:
我打开了/etc/apache2/conf.d/charset并删除了;从这一行:
AddDefaultCharset UTF-8
然后我重新启动了apache2和mysql,现在它可以正常工作了.
后来那个GitHub Core Hack 就像是一种享受.我最终做到了.
I'm learning laravel, and I'm stuck on a simple process. I want the tables to be generated as UTF-8 but varchar and text fields are like latin-1.
Schema section in guide did not help at all. I found this GitHub entry but it does not work neither (throws me errors).
I have a schema like this:
<?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');
}
}
This is the SQL output:
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 ;
But this is what I need:
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;
I even put collation
key to my 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' => '',
),
What am I missing, how do I fix this?
Thanks,
Just solved it, (using mysql 5.5 (5.5.29)) with Linux Mint 13 Mate (based on Ubuntu 12.04 LTS)
I added these lines on /etc/mysqld/my.cnf
[client]
default-character-set = utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
character-set-server = utf8
collation-server = utf8_unicode_ci
This way, SQL queries worked on shell as it should, but on laravel or phpmyadmin etc, they didn't work. So I did this:
I opened /etc/apache2/conf.d/charset and removed the ; from this line:
AddDefaultCharset UTF-8
Then I restarted apache2 and mysql, now it works as it should.
Later Edit: That GitHub Core Hack works like a treat. I ended up doing it.
这篇关于Laravel 3模式表列排序规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!