mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-3794: Cannot set default value on a @joinColumn #4649
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 @doctrinebot on GitHub (Jun 25, 2015).
Originally assigned to: @Ocramius on GitHub.
Jira issue originally created by user bmeynell:
The
@Columnallows for {{options={"default":1})}}.However,
@joinColumndoes not support {{options={"default":1})}}.The implication of this is that a default value can never be set for new database schemas and for existing schemas that have
DEFAULT '1'included in its column definition a schema mismatch will occur when runningdoctrine:schema:validate.Since there is no way to define a default on the entity-level there is no way to reconcile the mismatch. Instead, the default value just be removed from the database schema and be enforced on the application level.
@doctrinebot commented on GitHub (Oct 12, 2015):
Comment created by fbnatvista:
I'm not sure if there is any controindication bu adding Column annotation with the JoinColumn may bypass the problem:
@doctrinebot commented on GitHub (Oct 25, 2015):
Comment created by pat1498:
Sorry, I accidentally pressed the 'request feedback' button. I just wanted to say, the proposed solution does not seem to work. When I add the extra ORM\Column annotation, and run a migrations:diff... the migration shows that the foreign key and index will be dropped.
I have also tried using the columnDefinition annotation inside JoinColumn, but it doesn't seem to get picked up by a diff.
@maior-valentin commented on GitHub (May 5, 2016):
Hey guys. Any news on this?
@hmillet commented on GitHub (Jun 11, 2016):
+1
@daniel-adlantic commented on GitHub (Jul 6, 2016):
+1
I'd be interested in a solution or fix for this too.
In XML config I'm trying this:
However schema update is coming up with:
Where I would expect
Edit: Fix expected result default.
@smarcet commented on GitHub (Jul 6, 2016):
+1
yes this is particular usefull for legacy schemas, i had to tweak the BasicEntityPersister::prepareUpdateData method :/
@Ocramius commented on GitHub (Jul 6, 2016):
This is semantically incorrect, and will also break the ORM.
NULLisNULL, it's not0,1,"potato"or your legacy system's understanding of whatNULLactually is.NULLassociation doesn't get hydrated into a proxy, while a non-null one will be turned into a proxy, and then your lazy-loading would crash.INSERToperation, causing potential FK integrity issues when managed freshly inserted entities with default DB-side attributes are not refreshed after a successfulflush()operation. The ORM will assume that the inserted values are the real ones, while the DB actually changed them internally, automatically.Therefore, default values in associations or fields do not make sense in ORM context. Please customize your DDL in a migration file, instead of pushing this responsibility down to the ORM mapping tools.
@daniel-adlantic commented on GitHub (Jul 7, 2016):
I agree,
NULLisNULL. I'm not looking to substituteNULLwith another value like0or1. My default value1would be a reference to the associated table where there must be a row with identifier1. I'd expect the system to crash if the referenced record does not exist.@Ocramius commented on GitHub (Jul 7, 2016):
Note that setting a default association value still wouldn't work due to
reasons I explained above
On 7 Jul 2016 10:48 a.m., "daniel-adlantic" notifications@github.com
wrote:
@smarcet commented on GitHub (Jul 7, 2016):
i understand that, but i am tied to a MYSQL schema defined on that way, BC i am using and accesing aThird party Silverstripe DB that is defined on that way, so i cant change the MYSQL schema sadly
https://docs.silverstripe.org/en/3.2/developer_guides/model/data_model_and_orm/
cheers
@Ocramius commented on GitHub (Jul 7, 2016):
A couple things:
doctrine/migrationsto define the schema: not the raw schema tool from DBAL+ORM.@FaizRasool commented on GitHub (Aug 15, 2019):
Thats how i fixed it
@duzenko commented on GitHub (Sep 23, 2022):
columnDefinitiondid nothing for me, same integrity constraint violation