symfony 3学说schema_filter不起作用 [英] symfony 3 doctrine schema_filter not working
问题描述
我已经在我的数据库和相应的实体上创建了视图。一切似乎都正常,但是每当我运行
I have created views on my db and the corresponding Entity. All seems to work fine but whenever I run
php bin / console doctrine:schema:validate
php bin/console doctrine:schema:validate
它将告诉我映射是好的,但不是db,如下所示:
it will tell me that the mapping is fine, but not the db, as follows:
[数据库]失败-数据库架构与当前映射文件不同步。
[Database] FAIL - The database schema is not in sync with the current mapping file.
查找它,我发现可以将DBAL配置为从验证中过滤出表格。
Looking it up I found that one can configure DBAL to filter out tables from validation.
这是我在config.yml上尝试过的内容(请查看下面代码的最后一行)。目的是从验证中排除名称以 view开头的表。
This is what I attempted on config.yml ( check last line on code below). The intention is to exclude tables whose name start with "view" from validation.
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
schema_filter: ~^(?!view_)~
所以,根据文档的schema_filter应该将其过滤掉,但是
So, the schema_filter as per this documentation should filter that out, but it doesn't.
我检查了其他几个问题,包括这
I checked a few other questions, including this
有什么想法吗?
谢谢
Any ideas? Thanks
推荐答案
消息告诉您,您的映射与数据库架构不同,必须更新数据库方案。
对于Symfony3命令是
Message tell you that your mapping it's not the same as your database schema, you must update your database scheme. For Symfony3 command is
php bin/console doctrine:schema:update --force
实际上,此命令功能非常强大。它将
数据库的外观(基于
实体的映射信息)与实际外观进行比较,并执行将数据库模式更新到所需位置的SQL语句
应该是
Actually, this command is incredibly powerful. It compares what your database should look like (based on the mapping information of your entities) with how it actually looks, and executes the SQL statements needed to update the database schema to where it should be
您也可以使用
php bin/console doctrine:schema:update --dump-sql
查看SQL需要运行,但无需更改数据库方案。
to see SQL you need to run, but without the change database scheme.
运行时
php bin/console doctrine:schema:validate
Doctrine将检查您的映射文件还可以
之后,将检查您的架构。在那一刻,您的参数 schema_filter
告诉Doctrine忽略数据库中所有以 view 开头的表,但是在映射文件中存在具有表名的实体 view ... ,为此,您会出错
Doctrine will check your mapping files and for you is ok.
After that will check your schema. In that moment your parameter schema_filter
tell Doctrine to ignore all tables in database which name start with view, but in your mapping files exist entity with table name view... and for that you getting error
[数据库]失败-数据库架构不在与当前映射文件同步。
[Database] FAIL - The database schema is not in sync with the current mapping file.
所以 schema_filter
用来告诉原则是忽略数据库中的表而不忽略实体。
So the schema_filter
is use to tell Doctrine to ignore tables in database and not to ignore entities.
看看何时使用 schema_filter
想象一下您需要在数据库中使用名称以 custom _ ,在文件中您没有与此表映射的实体,并且如果调用
To see when to use schema_filter
imagine situation that you need custom tables in database with names that start with custom_ , in your files you don't have entities mapped with this tables and if you call
php bin/console doctrine:migrations:diff
这将删除所有自定义表,除非您在配置文件中告诉Doctrine忽略自定义表,如果设置参数
this will drop all custom tables, except if you in your config file tell Doctrine to ignore custom tables and you can do that if set up parameter
schema_filter: ~^(?!custom_)~
请检查文档文档
这篇关于symfony 3学说schema_filter不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!