spotorm / spot2

Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer
http://phpdatamapper.com
BSD 3-Clause "New" or "Revised" License
601 stars 101 forks source link

Upgrade to 2.2.0 breaks a running project #235

Closed mmethner closed 6 years ago

mmethner commented 7 years ago

Hi,

after upgrading from 2.17 to 2.2.0 my current project breaks. Looks, like the foreign key support causes an exception on existing data sets, while I call ->migrate() to update the scheme.

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (booking_1.#sql-61b8_2fa, CONSTRAINTusr_bookings_fk_discountFOREIGN KEY (discount_id) REFERENCESusr_discounts(id) ON DELETE SET NULL ON UPDATE CASCADE)

Is there a way to disable the foreign key support?

Best regards Mathias

tuupola commented 7 years ago

Reading the commit history (https://github.com/spotorm/spot2/commit/1a70172c3b247ce8792bb7e9456de0cab924f5b0) there seems to be foreignkey setting with defaults to true. Not sure if it is related. Seems 2.2.0 also broke Postgres migrations see #183.

mmethner commented 7 years ago

Ok. Thanks for your hint.

mmethner commented 6 years ago

You need to set 'foreignkey' => false on every field, which is a reference to a foreign table. That solution is not perfect, but it works.