Ability to disable FOREIGN KEY CONSTRAINT when using Doctrine generate migration #6282

Closed
opened 2026-01-22 15:30:06 +01:00 by admin · 3 comments
Owner

Originally created by @TangMonk on GitHub (Aug 12, 2019).

Originally assigned to: @Ocramius on GitHub.

Feature Request

Q A
New Feature yes
RFC yes/no
BC Break yes/no

Summary

Guaranteed constraints require additional computing resources. The application server is easier to scale horizontally than the database server, so the constraints should be placed in the business logic.

I often change/add some field in Entity and using bin/console make:migration to generate migrations, that's convenience just like in Rails or Django. But I do not need Foreign Key Constraint when I using Doctrine Relationships(ManyToOne, OneToMany...).

I have to delete lines contained Foreign Key Constraint in generated migrations. But When I doing some changes with Entity, and run bin/console make:migration, It will add Foreign Key Constraint again, it is annoying.

In django model ForeignKey you can set db_constraint=False, so migration would not generate Foreign Key constraint

Originally created by @TangMonk on GitHub (Aug 12, 2019). Originally assigned to: @Ocramius on GitHub. ### Feature Request | Q | A |------------ | ------ | New Feature | yes | RFC | yes/no | BC Break | yes/no #### Summary Guaranteed constraints require additional computing resources. The application server is easier to scale horizontally than the database server, so the constraints should be placed in the business logic. I often change/add some field in Entity and using `bin/console make:migration` to generate migrations, that's convenience just like in Rails or Django. But I do not need Foreign Key Constraint when I using Doctrine Relationships(ManyToOne, OneToMany...). I have to delete lines contained Foreign Key Constraint in generated migrations. But When I doing some changes with Entity, and run `bin/console make:migration`, It will add Foreign Key Constraint again, it is annoying. In django model ForeignKey you can set `db_constraint=False`, so migration would not generate Foreign Key constraint
admin added the New FeatureWon't FixQuestion labels 2026-01-22 15:30:06 +01:00
admin closed this issue 2026-01-22 15:30:06 +01:00
Author
Owner

@Ocramius commented on GitHub (Aug 12, 2019):

If you don't want foreign keys, you can use a custom DB platform that disables foreign key support.

Besides that, migrations are to be checked one by one anyway, before being committed.

@Ocramius commented on GitHub (Aug 12, 2019): If you don't want foreign keys, you can use a custom DB platform that disables foreign key support. Besides that, migrations are to be checked one by one anyway, before being committed.
Author
Owner

@slince commented on GitHub (Jan 29, 2023):

@Ocramius

If you don't want foreign keys, you can use a custom DB platform that disables foreign key support.

this way is no longer working in the lastest version.

@slince commented on GitHub (Jan 29, 2023): @Ocramius > If you don't want foreign keys, you can use a custom DB platform that disables foreign key support. this way is no longer working in the lastest version.
Author
Owner

@Ocramius commented on GitHub (Jan 29, 2023):

Time to learn about respecting foreign keys 😁

Disabling FKs during a migration can still be done on some platforms (notably MySQL).

@Ocramius commented on GitHub (Jan 29, 2023): Time to learn about respecting foreign keys 😁 Disabling FKs during a migration can still be done on some platforms (notably MySQL).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6282