-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validation Error in doctrine:schema:validate After Merging PR #6418 #6437
Comments
According to this #6390, I understand that there is a need to somehow track changes in the name of a foreign key (but I really don't know why). However, this breaks the ability to create named foreign keys, which has been in existence for near 10 years, and no alternative has been proposed for creating named foreign keys. |
Cc @achterin |
@berkut1 thanks for your bug report. i'll have a look at this asap. in my opinion doctrine should always keep track of the foreign key names because it already does so for indexes. but i also agree that having support for named foreign keys is a must. |
@achterin Thanks. |
But then i suspect your definitions to be wrong as doctrine is creating an empty table diff if i specifically name the foreign keys in a test:
as to your comment about my issue: i agree with you that migrating up and down would also solve the issue. but thats not the point. the whole point of doctrine is to keep the database schema in sync with the definition in code. and if a database has a foreign key that has a different name compared to the definition, the comperator should pick this up. otherwise two databases can have two different foreign key names which means they are out of sync and doctrine is happy with both schemas. thats a bug in my book. |
But if this has been acceptable for 10 years and is used by programmers, can it really be considered a bug? |
I just read the name of the test that used to be UPD: |
and as i said in the pr, this was also the case for indexes and yet this behavior was changed. so first of all we should keep the behavior as it is now, as it is the right thing to do but also find a way to support named foreign keys. but i guess this is not the task of the dbal layer but the orm because the dbal layer supports named foreign keys just fine. the only thing is that the orm layer doesnt support this to my knowledge and it looks like it is not going to which worries me: doctrine/orm#3753 (comment) |
as i said and already have proven with the posted test: the dbal layer already supports named foreign keys just fine. the only issue is that the orm layer does not. but i guess we should align this with the project managers as i agree with you that the current implementation will break custom named foreign keys of users that have been told to do just that. and yes, this will be a problem but can be sorted out. |
After digging a bit more into this topic I'm even more convinced that the orm preject needs to decide if they want to support named foreign keys (I'm willing to develop a pr for that if necessary) or not - letting users to custom changes to a database leads to issues as this one. |
Hmm, I see it might be important if you dynamically create and modify schemas, for example, for a CMS. However, the conditions for generating a foreign key dbal/src/Schema/AbstractAsset.php Lines 148 to 155 in 8edbce7
apply when the table name or attribute name changes. But this will work even without your fix because Doctrine will notice that the attributes or table name have changed and will recreate the foreign keys. In that case, in what situations could the generated key name become outdated after the first migration? If the algorithm for crc32() changes after updating PHP or libraries in the OS? But wouldn't that still lead to the same situation where we get different foreign key names during dropSchema() if we haven't specifically synchronized the schemas before?
|
This change has also made 3.8.5 a breaking release across all our projects, which is unfortunate. We run a database schema validation as part of our CI flow, after applying database migrations, to ensure that the migrated database is in sync with the doctrine schema tagging. These are all now failing because foreign key names don't match. The mismatches are for one of two reasons:
I can see there might be a purist argument for tracking the names as well as the definitions, and I don't object to that in principle (especially since index names are validated). However, I don't think that can be made mandatory in a point release unless there's a way for users to solve the validation failure by customising the doctrine schema so the expected name matches the existing database. Certainly for mysql, a Foreign Key can only be renamed by dropping it and recreating it, which is potentially both an expensive and risky migration to run and I'm really not keen to do that across all our tables and projects. Particularly since evidently doctrine's auto-naming strategy has already changed at some point in the past, and could change again in future, and it feels wrong if users are forced to change existing database schemas if & when that happens. In my opinion, assuming ORM don't have immediate plans to support customising FK names, this behaviour should either be reverted or made opt-in in the next 3.8.x point release. |
Agreed, please send a revert PR then it can be reintroduced with an opt in mechanism in 3.9 |
@greg0ire But these changes also affect the 4.0.x version, or in this case, will everyone affected on 4.0 have to downgrade to version 3.8.x? |
No, we'll just merge up the revert |
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. |
Bug Report
Summary
The PR #6418 breaks
doctrine:schema:validate
and prevents validation, suggesting replacing allCONSTRAINT
definitions, especially those with theFOREIGN KEY
.Removing the problematic line resolves the issue:
dbal/src/Schema/Comparator.php
Lines 374 to 376 in 8edbce7
Current behaviour
doctrine:schema:validate
fails validation and suggests replacing all foreign keyCONSTRAINT
definitions that include theFOREIGN KEY
.How to reproduce
Run
doctrine:schema:validate
Observe the validation errors related to foreign key
CONSTRAINT
definitions withFOREIGN KEY
Example configuration causing the issue:
validation schema errors
It also completely ignores theRe-tested that is not true.ON DELETE RESTRICT
rule, completely removing it.Expected behaviour
doctrine:schema:validate
should successfully validate the schema without suggesting changes toCONSTRAINT
definitions, including those with theFOREIGN KEY
The text was updated successfully, but these errors were encountered: