我正在使用symfony命令通过运行以下命令从我的mysql 5.1数据库生成schema.yml文件:
symfony doctrine:build-schema
我的表:
CREATE TABLE `identity` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`username` VARCHAR(64) DEFAULT NULL,
`password` VARCHAR(128) DEFAULT NULL
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=INNODB DEFAULT CHARSET=latin1
转换为:
Identity:
connection: doctrine
tableName: identity
columns:
id:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: true
username:
type: string(64)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
password:
type: string(128)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
一切看起来都不错,除非我期望用户名栏看起来像(例如unique: true
):
username:
type: string(64)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
unique: true
有谁知道我错过了什么?
答案 0 :(得分:0)
试试这个:
CREATE TABLE `identity` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`username` VARCHAR(64) DEFAULT NULL UNIQUE,
`password` VARCHAR(128) DEFAULT NULL
PRIMARY KEY (`id`),
UNIQUE INDEX `identity_username_idx` (`username`)
) ENGINE=INNODB DEFAULT CHARSET=latin1
答案 1 :(得分:0)
尝试命名除(column)
或(column)_idx
以外的密钥; e.g:
CREATE TABLE `identity` (
...
UNIQUE KEY `username_unique` (`username`)
) ...
我无法在任何地方找到此文档,但我在创建Doctrine行为时注意到,如果我尝试创建名称与列匹配的索引,则Doctrine会将其重命名为(column)_idx
并拒绝使其唯一