【问题标题】:doctrine:build-schema ignoring unique key学说:忽略唯一键的构建模式
【发布时间】:2011-02-22 23:07:25
【问题描述】:

我正在使用 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

有人知道我错过了什么吗?

【问题讨论】:

    标签: mysql symfony1 doctrine


    【解决方案1】:

    试试这个:

    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
    

    【讨论】:

      【解决方案2】:

      尝试将密钥命名为 (column)(column)_idx 以外的其他名称;例如:

      CREATE TABLE `identity` (
        ...
      
        UNIQUE KEY `username_unique` (`username`)
      ) ...
      

      我在任何地方都找不到此文档,但我在创建 Doctrine 行为时注意到,如果我尝试创建名称与列匹配的索引,Doctrine 会将其重命名为 (column)_idx 并拒绝使其唯一。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-10-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-06
        • 1970-01-01
        相关资源
        最近更新 更多