Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Error deleting a object with that has many objects. Exception: "Primary key cannot be changed"
  • Hi there, I've been trying for too long now to fix this on my own, but I'm lost, I really don't know what I did wrong. Schema: http://i.imgur.com/GSyLx.png Models:
    printeroptions.php - http://scrp.at/aKz
    printers.php - http://scrp.at/aKA
    printersoptions.php - http://scrp.at/aKB FuelVersion: 1.0.1 When I try to delete a printer using: public function action_delete($printer_id)
    {
    $entry = Model_Printers::find($printer_id);
    $entry->delete();
    \Response::redirect("bo/printers/view");
    } I get "Fuel\Core\Fuel_Exception [ Error ]: Primary key cannot be changed."
    Any idea what am I doing wrong? Thanks!
    MJS
  • You're using primary keys as foreign keys in the PrintersOptions model, which is expressly not allowed just because PKs can't be changed. From the docs:
    The primary key must be a real primary key: unique and unchanging. Don't use it for other purposes (like a foreign key in a one-one relation) as well, that won't work as the PK can't be changed. The Orm won't check this, and while it might seem to work at first glance: you'll get into trouble. - Creating models
  • Hi Jelmer, that was indeed the problem. Tks buddy!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion