mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Force Doctrien to create GUID fields as VARCHAR(255) or to update exsting fields to CHAR(36) #5297
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @SDPrio on GitHub (Oct 20, 2016).
I am using Doctrine within a Symfony 2.8 project. The entities / DB tables within the project are using a
GUIDfield as ID. In previous Doctrine Versions these field where created asVARCHAR(255), while after an Update (see below), they are now created asCHAR(36):The code change can be found in
dbal/lib/Doctrine/DBAL/Platforms/AbstractPlatform.phpin thegetGuidTypeDeclarationSQLmethod.Of course it makes sense to store GUIDs as
CHAR(36)since this is their defined length and thus aVARCHAR(255)wastes space. However this change brings up a new Problem:I added a new entity that should use a
ManyToOnerelationship to an existing entity via itsguidfield:Doctrine dumps the following SQL staments to create the table for the
NewEntitywhen usingphp app/console doctrine:schema:update --dump-sql:The execution however fails with
The problem is, that the
guidfield ofother_entityis defined asVARCHAR(255)(created with old Doctrine version), while theother_guidfield ofnew_entityis now created asCHAR(36). Mapping field of different types is not possible and leads to the error shown above. When I manually create thenew_entitytable usingVARCHAR(255)instead, everything works fine.How can I solve this?
Is it possible to force Doctrine to create guidas as
VARCHAR(255)? Of course it would be better to update the existing tables to also useCHAR(36), butdoctrine:schema:updatedoes not do that.Any idea?
@Ocramius commented on GitHub (Oct 25, 2016):
@SDPrio what you are hitting is a schema upgrade issue. Just needs a manual migration for now, where the altering is done on both sides, and the FK is added afterwards.
If I get this correctly, doctrine is not doing that, and therefore you have the issue. Is it possible for you to try simulating this scenario with just the DBAL schema diffing tools, in a test case?