Open SDPrio opened 7 years ago
@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?
I am using Doctrine within a Symfony 2.8 project. The entities / DB tables within the project are using a
GUID
field 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.php
in thegetGuidTypeDeclarationSQL
method.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
ManyToOne
relationship to an existing entity via itsguid
field:Doctrine dumps the following SQL staments to create the table for the
NewEntity
when usingphp app/console doctrine:schema:update --dump-sql
:The execution however fails with
The problem is, that the
guid
field ofother_entity
is defined asVARCHAR(255)
(created with old Doctrine version), while theother_guid
field ofnew_entity
is now created asCHAR(36)
. Mapping field of different types is not possible and leads to the error shown above. When I manually create thenew_entity
table 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:update
does not do that.Any idea?