数据库失败 - 数据库架构与当前映射文件不同步 [英] Database FAIL - The database schema is not in sync with the current mapping file

查看:36
本文介绍了数据库失败 - 数据库架构与当前映射文件不同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释以下教义模式验证错误消息:

Can anybody explain the following doctrine schema validation error message please:

这是 manyToMany 关系中每个实体的 yaml ORM 定义,根据 文档.

Here is the the yaml ORM definition of each entity in the manyToMany relationship, created inline with section 5.9 of the documentation.

RepBundleProjectBundleEntityUser:
    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: {  }

和 UserRole 反向 yaml 配置:

And the UserRole inverse yaml configuration:

RepBundleProjectBundleEntityUserRole:
    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: {  }

这是用户表架构:

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;

UserRole 表架构:

The UserRole table schema:

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;

以及 UserRoleLookup 架构:

And the UserRoleLookup schema:

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;

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

As you can see, it's a pretty simplistic setup with a look-up table to dictate a user's roles or the set of users in a given user role. However, I'm receiving this frustrating synch error. I've read nothing here or online which answers this question in any concise detail, I was hoping someone could clarify if I am safe to leave this configuration and ignore this error?

推荐答案

运行此命令以显示 SQL 中的差异,而无需转储您的数据库:

Run this command to show the differences in the SQL without having to dump your db:

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

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

You can also run the following command to perform the changes:

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

对于 symfony2 来说是

For symfony2 it was

php 应用程序/控制台学说:schema:update --force --full-database

这篇关于数据库失败 - 数据库架构与当前映射文件不同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆