If your application needs to hold some custom (unmapped) tables in the database, then generating migrations with doctrine-migrations diff will try to drop the custom tables. This article provides a solution on how to avoid dropping those tables.
Run the following command in your application’s root directory:
If you have mapping modifications, this will create a new migration file under data/doctrine/migrations/ directory. Opening the migration file, you will notice that it contains some queries that will drop your
oauth_* tables because they are unmapped (there is no doctrine entity describing them). You should delete your latest migration with the DROP queries in it as we will create another one, without the DROP queries in it. In order to avoid dropping these tables, you need to add a parameter called filter-expression.
The command to be executed without dropping these tables looks like this:
On Windows (use double quotes):
vendor/bin/doctrine-migrations diff --filter-expression="/^(?!oauth_)/"
On Linux/macOS (use single quotes):
vendor/bin/doctrine-migrations diff --filter-expression='/^(?!oauth_)/'
Filtering multiple unmapped table patterns
If your database contains multiple unmapped table groups, then the pattern in
filter-expression should hold all table prefixes concatenated by pipe character (
|). For example, if you need to filter tables prefixed with
bar_, then the command should look like this:
vendor/bin/doctrine-migrations diff --filter-expression="/^(?!foo_|bar_)/"
vendor/bin/doctrine-migrations diff --filter-expression='/^(?!foo_|bar_)/'
On Windows, running the command in PowerShell might still add the
DROP TABLE oauth_* queries to the migration file. This happens because for PowerShell the caret (
^) is a special character, so it gets dropped (
"/(?!oauth_)/" when it reaches your command). Escaping it will not help either.
In this case, we recommend running the command:
- directly from your IDE
- from the
You can get more help with this command by running:
vendor/bin/doctrine-migrations help diff