doctrine / dbal

Doctrine Database Abstraction Layer
https://www.doctrine-project.org/projects/dbal.html
MIT License
9.48k stars 1.34k forks source link

Comparison Problem Default 'NULL' #2817

Closed ndoulgeridis closed 6 years ago

ndoulgeridis commented 7 years ago

I am using

PHP                                  v7.1.7
MariaDB                              v10.2.7
doctrine/annotations                 v1.2.7    Docblock Annotations Parser
doctrine/cache                       v1.6.2    Caching library offering an object-oriented API for many cache    backends
doctrine/collections                 v1.3.0    Collections Abstraction library
doctrine/common                      v2.6.2    Common Library for Doctrine projects
doctrine/data-fixtures               v1.1.1    Data Fixtures for all Doctrine Object Managers
doctrine/dbal                        v2.5.13   Database Abstraction Layer
doctrine/doctrine-bundle             1.6.8     Symfony DoctrineBundle
doctrine/doctrine-cache-bundle       1.3.0     Symfony Bundle for Doctrine Cache
doctrine/doctrine-fixtures-bundle    2.3.0     Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle  v1.1.0    Symfony DoctrineMigrationsBundle

When I run command:

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

I get every time same queries run and of course with

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

I see every time the same SQL Queries (all of them ALTER).

So I have troubleshooted it a bit and found the following issue in:

vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Comparator.php:210

$table1Columns = $table1->getColumns();
$table2Columns = $table2->getColumns();

More precisely the problem is on :

 vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Comparator.php:438

  if ($properties1['default'] != $properties2['default'] ||
        // Null values need to be checked additionally as they tell whether to create or drop a default value.
        // null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation.
        (null === $properties1['default'] && null !== $properties2['default']) ||
        (null === $properties2['default'] && null !== $properties1['default'])
    ) {
        $changedProperties[] = 'default';
    }

The problem is that default null is different type. In table 1 is string "NULL" while in second table is a null type. Probably here need to cast or also check if property value is "NULL".

dbal-bug

Is this a known issue? Any workarounds how to fix this one? It should be a new issue due to PHP version or MySQL/MariaDB because it's impossible to be unspotted so far.

Ocramius commented 7 years ago

Probably here need to cast or also check if property value is "NULL".

"NULL" is not NULL: one is a string, the other one is the absence of value.

Please check if this issue matches any of the following:

ste93cry commented 7 years ago

After updating to MariaDB 10.2 on a CentOS server I'm experiencing the same problem. I just dumped the database from the server and imported it into MySQL on Windows and there is nothing to update according to the doctrine:schema:update --dump-sql command. However on the server all fields are marked as needing update when they shouldn't

sagaraspl commented 7 years ago

Hi @crash21 and @Ocramius I am facing the same issue after updating to MariaDB 10.2.7

belgattitude commented 7 years ago

Just found possible approaches to fix:

see my comment on https://github.com/doctrine/doctrine2/issues/6565

I'll publish a P/R soon

Seb

belgattitude commented 7 years ago

Here's a P/R: https://github.com/doctrine/dbal/pull/2825.

Feel free to test and comment.

Majkl578 commented 6 years ago

This is duplicate of doctrine/doctrine2#6565 and should be fixed by #2825.

github-actions[bot] commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.