开发者

doctrine:build-schema ignoring unique key

i am using the symfony command to generate my schema.yml file from my mysql 5.1 database by running:

symfony doctrine:build-schema

My table:

CREATE TABLE `identity` (
  `i开发者_如何学God` 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

Gets converted into:

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

It all looks fine, except i'm expecting the username column to look like (e.g. with the unique: true):

    username:
      type: string(64)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
      unique: true

Does anyone know what i am missing?


Try this:

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


Try naming the key something other than (column) or (column)_idx; e.g.:

CREATE TABLE `identity` (
  ...

  UNIQUE KEY `username_unique` (`username`)
) ...

I can't find this documented anywhere, but I noticed while creating a Doctrine behavior that if I try to create an index whose name matches a column, Doctrine will rename it to (column)_idx and refuse to make it unique.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜