Doctrine recreates the same index - symfony

When I run doctrine schema update, I am getting this weird queries that need to be executed but they are basically just redoing already done or not?
php app/console doctrine:schema:update --dump-sql
DROP INDEX idx_26d7e8feab772a3c ON notify;
CREATE INDEX IDX_217BEDC8AB772A3C ON notify (notifyUser_id);
DROP INDEX idx_26d7e8fea76ed395 ON notify;
CREATE INDEX IDX_217BEDC8A76ED395 ON notify (user_id);
DROP INDEX idx_26d7e8fe6bf700bd ON notify;
CREATE INDEX IDX_217BEDC86BF700BD ON notify (status_id);
"require": {
"php": ">=5.3.3",
"symfony/symfony": "~2.5.3",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "~1.2",
"gedmo/doctrine-extensions": "2.3.*#dev",
"stof/doctrine-extensions-bundle": "~1.1#dev",
},
This behaviour stops me from updating doctrine schema with --force because there are foreign keys and I get this error:
[PDOException]
SQLSTATE[HY000]: General error: 1553 Cannot drop index 'IDX_A37CA197A76ED395': neede
d in a foreign key constraint
This started to happening probably after updating DB related vendors in past but I haven't notice it until now.

#theapprenticecoder #Trki this problem can be solve by the command
$ app/console doctrine:schema:update --force --complete
which is the best solution.

I can confirm you that this probably happened when you upgraded Doctrine Vendors.
This issue was fixed with the doctrine/dbal 2.5.1 version.
All you need to do is install the v2.5.1 doctrine/dbal dependency.
Then just do a "php app/console doctrine:schema:update --force" and your problem will be solved...

Related

doctrine migrations configuration: kernel.project_dir is not interpolated

I'm trying to generate and execute migrations using doctrine/doctrine-migrations-bundle.
Project specs:
Project deployed in docker. Mapping configured successfully.
Framework: symfony.
Kernel::getProjectDir() overrided successfully.
Project dependencies (not all, only important for this topic) from composer.json:
"doctrine/doctrine-bundle": "^2.1",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.7",
"symfony/framework-bundle": "5.1.*",
My project has migrations for two databases. There are 2 config files for this. An example of one of them for understanding (absolute path in container /opt/app/config/packages/migrations/some_config.yaml):
custom_template: '%kernel.project_dir%/config/migration_template.txt' # <- this not works
# custom_template: '/opt/app/config/migration_template.txt' # <- this works
em: some_em
transactional: false
migrations_paths:
'DoctrineMigrations': '%kernel.project_dir%/src/DoctrineMigrations' # <- this not works
#'DoctrineMigrations': '/opt/app/src/DoctrineMigrations' # <- this works
Problem:
I'm trying to generate migration, using following command:
bin/console doctrine:migrations:generate --configuration='/opt/app/config/packages/migrations/some_config.yaml'
An exception is thrown with an message:
The specified template "%kernel.project_dir%/config/migration_template.txt" cannot be found or is not readable
For absolute path everything works fine.
I have tried to debug doctrine-migrations package code and found, that path %kernel.project_dir%/config/migration_template.txt does not turn into /opt/app/config/migration_template.txt
I think the problem is that the command is implemented in the doctrine/migrations lib and is unaware of Symfony, and therefore doesn't know about container parameters. The Doctrine migrations docs have an example for such a path, so you might try this:
'./src/DoctrineMigrations'
(didn't try myself though).
The relevant part in the docs is here: https://www.doctrine-project.org/projects/doctrine-migrations/en/3.6/reference/configuration.html#configuration

Symfony console component: There are no commands defined in the "make" namespace

I am trying to add few Symfony components in a legacy project in order to leverage it (I would rather avoid using the full Symfony framework). That works very well with http-foundation and routing. Now I am trying to add Doctrine and I would like to create entities thanks to the Symfony console component.
I have installed the following packages:
"require": {
"symfony/error-handler": "^6.2",
"symfony/http-foundation": "^6.2",
"symfony/http-kernel": "^6.2",
"symfony/routing": "^6.2",
"symfony/console": "^6.2",
"symfony/security-bundle": "^6.2",
"symfony/orm-pack": "^2.2",
"doctrine/orm": "^2.13",
"doctrine/doctrine-bundle": "^2.7",
"doctrine/doctrine-migrations-bundle": "^3.2"
},
"require-dev": {
"symfony/maker-bundle": "^1.48"
}
And wrote the console file
#!/usr/bin/env php
<?php
// bin/console
require __DIR__.'/../vendor/autoload.php';
use Symfony\Component\Console\Application;
$application = new Application();
$application->run();
But I get this error message when creating an Entity:
$php bin/console make:entity Product
There are no commands defined in the "make" namespace.
Here is the list of command I get with console list
php bin/console list
Console Tool
Usage:
command [options] [arguments]
Options:
-h, --help Display help for the given command. When no command is given display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
completion Dump the shell completion script
help Display help for a command
list List commands
How could I register the commands from Doctrine into Symfony console?
Thanks!

--allow-empty-diff stopped working after upgrading to doctrine migrations 3

I have a deployment script that executes the migrations this way:
php bin/console doctrine:migrations:diff --allow-empty-diff --env=prod
php bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration --env=prod
And I am getting this error:
[ERROR] No changes detected in your mapping information.
Previously, before upgrading to migrations 3, the error was not being thrown. Once I upgraded it the error started to appear.
"doctrine/doctrine-bundle": "2.1.*",
"doctrine/doctrine-migrations-bundle": "3.1.*", // previously "2.2.*"
"doctrine/migrations": "3.2.*", // previously "2.2.*"
At first I thought that the --allow-empty-diff was removed in the new version, but when I run:
php bin/console doctrine:migrations:diff --help
I do see
--allow-empty-diff Do not throw an exception when no changes are detected.
Any ideas?
It seems the functionality stills works the same as before. If no changes are detected, a message is printed to the console.
However, the difference between 2.2.* and 3.6.* is that it the latter uses StyleInterface to style the message as an error instead of using the regular OutputInterface.
In both cases, a exception is not thrown.
See the code for 2.2.*
See the code for 3.6.*
Just give a try updating your schema
php bin/console orm:schema-tool:update --force

Symfony 4.4 AnnotationDriver

When I use: php bin/console make:entity, I get the following error:
"Doctrine\Persistence\Mapping\Driver\AnnotationDriver" does not exist.
Symfony 4.4 support has been dropped for the maker bundle.
You need to upgrade your symfony version (it's not that hard from 4.4 to 5.4).
However, there is a temporary fix if you want by modifying your composer.json and downgrade your doctrine/orm to 2.11 until you migrate to symfony 5.4.
Change your composer.json with:
"doctrine/orm": "2.11.*",
And also:
"conflict": {
"symfony/symfony": "*",
"doctrine/orm": "2.12.0"
},
Don't forget to run composer update

Updating fields doctrine symfony mysql

Here is the code on the console.
ubuntu1256:~/httpdocs/site$ php app/console doctrine:schema:update --dump-sql
ALTER TABLE campaign CHANGE adresse_email_business_partner adresse_email_business_partner VARCHAR(255) DEFAULT NULL
ubuntu1256:~/httpdocs/site$ php app/console doctrine:schema:update --force
Updating database schema...
Database schema updated successfully! "1" queries were executed
I continue to force but it doesn't updates correctly. Any ideas? I wanted to add a field in a class.

Resources