Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
error when deleting
  • What's up. I have the following code with which I'm trying to simply delete 1 record of my table:
    $character = \Model_Character::find($id); $character->delete();

    I don't think there is anything wrong with this code, but for some reason I get this error:
    Fuel\Core\FuelException [ Error ]: Primary key cannot be changed.

    The record has been deleted though, so if anyone can tell me what I'm doing wrong here that would be great. Thanks in advance!
  • Are you using primary keys as foreign keys as well? Also when posting an error it's more helpfull to post the full backtrace as well, that makes it a lot easier to track what is going on.
  • It maybe a bag of FuelPHP.
    I dealt with it in this way. @Namespace Orm class HasOne.
    (packages/orm/classes/hasone.php) public function delete($model_from, $model_to, $parent_deleted, $cascade) ---
    if ($model_to and ! $model_to->frozen())
    {
    foreach ($this->key_to as $fk)
    {
    $model_to->{$fk} = null;
    }
    } $cascade = is_null($cascade) ? $this->cascade_delete : (bool) $cascade;
    if ($cascade and ! empty($model_to))
    {
    $model_to->delete();
    } ==========>>>>>>>>>> $cascade = is_null($cascade) ? $this->cascade_delete : (bool) $cascade;
    if ($cascade and $model_to and ! $model_to->frozen())
    {
    foreach ($this->key_to as $fk)
    {
    $model_to->{$fk} = null;
    }
    } if ($cascade and ! empty($model_to))
    {
    $model_to->delete();
    }

Howdy, Stranger!

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

In this Discussion