数据库故障 - 数据库模式与当前映射文件不同步

Dan*_*den 12 yaml doctrine symfony doctrine-orm

任何人都可以解释以下doctrine架构验证错误消息:

架构验证函数返回的错误消息

以下是manyToMany关系中每个实体的yaml ORM定义,与文档的第5.9节内联创建.

Rep\Bundle\ProjectBundle\Entity\User:
    type: entity
    table: User
    fields:
        id:
            id: true
            type: integer
            unsigned: true
            nullable: false
            generator:
                strategy: AUTO
        username:
            type: string
            length: 25
            fixed: false
            nullable: false
        salt:
            type: string
            length: 32
            fixed: false
            nullable: false
        password:
            type: string
            length: 40
            fixed: false
            nullable: false
        email:
            type: string
            length: 60
            fixed: false
            nullable: false
    manyToMany:
        roles:
            targetEntity: UserRole
            inversedBy: users
            joinTable:
                name: UserRoleLookup
                joinColumns:
                    user_id:
                        referencedColumnName: id
                inverseJoinColumns:
                    user_role_id:
                        referencedColumnName: id
    lifecycleCallbacks: {  }
Run Code Online (Sandbox Code Playgroud)

和UserRole逆yaml配置:

Rep\Bundle\ProjectBundle\Entity\UserRole:
    type: entity
    table: UserRole
    fields:
        id:
            id: true
            type: integer
            unsigned: true
            nullable: false
            generator:
                strategy: AUTO
        name:
            type: string
            length: 50
            fixed: false
            nullable: false
    manyToMany:
        users:
            targetEntity: User
            mappedBy: roles
    lifecycleCallbacks: {  }
Run Code Online (Sandbox Code Playgroud)

这是User表架构:

CREATE TABLE `User` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
  `salt` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
  `password` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
  `email` varchar(60) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Run Code Online (Sandbox Code Playgroud)

UserRole表架构:

CREATE TABLE `UserRole` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Run Code Online (Sandbox Code Playgroud)

和UserRoleLookup架构:

CREATE TABLE `UserRoleLookup` (
  `user_id` int(11) unsigned NOT NULL,
  `user_role_id` int(11) unsigned NOT NULL,
  PRIMARY KEY (`user_id`,`user_role_id`),
  KEY `user_role_id` (`user_role_id`),
  CONSTRAINT `userrolelookup_ibfk_2` FOREIGN KEY (`user_role_id`) REFERENCES `userrole` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `userrolelookup_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,这是一个非常简单的设置,带有一个查找表来指定用户的角色或给定用户角色中的用户集.但是,我收到了这个令人沮丧的同步错误.我在这里或网上都没有读到任何简洁细节回答这个问题的内容,我希望有人可以澄清我是否可以安全地离开这个配置并忽略这个错误?

Ste*_*ber 27

运行此命令以显示SQL中的差异而不必转储数据库:

php bin/console doctrine:schema:update --dump-sql

您还可以运行以下命令来执行更改:

php bin/console doctrine:schema:update --force --full-database

对于symfony2它是

php app/console doctrine:schema:update --force --full-database

  • 好主意.它对我有用.当然,如果您使用zf2和doctrine/doctrine-orm-module,命令是"orm:schema:update" (3认同)
  • 只是要指出:请注意,控制台位于symfony 3上的bin目录中.*:$ php bin/console doctrine:schema:update --force --complete (3认同)
  • 看起来它被重命名为`-complete`:https://github.com/doctrine/doctrine2/blob/b055d78ea19835fab563dfc234d4804a9d04966a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php (2认同)
  • 多么无用的命令,不显示遇到的错误.:( (2认同)

Sta*_*Fad 7

对于Symfony3:

app/console改为bin/console--full-database--complete

所以最后的命令将是:

php bin/console doctrine:schema:update --force --complete --dump-sql
Run Code Online (Sandbox Code Playgroud)


gre*_*ire 5

这很简单:某些字段或关系或实体等尚未在数据库模式中转换为列或表.更新您的架构,你会没事的.