Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8667319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:56:11+00:00 2026-06-12T17:56:11+00:00

My problem is as follows. After deleting multiple rows from table, inserting new record

  • 0

My problem is as follows.

After deleting multiple rows from table, inserting new record into same table results in error.

Database Error
Error: SQLSTATE[42P01]: 
Undefined table: 7 ERROR: relation "order_details_id_seq" does not exist

Table

CREATE TABLE schema.order_details (
    id serial NOT NULL,
    order_id integer NOT NULL,
    field_1 integer,
    field_2 real,
    field_3 character varying(15),
    CONSTRAINT order_details_pkey PRIMARY KEY (id )
)
WITH (
    OIDS=FALSE
);

Insert is

INSERT INTO "schema"."order_details" ("order_id", "field_1", "field_2", "field_3")
VALUES (37, 1, 2, 'value');

Sequence “schema”.”order_details_id_seq” in used schema exists.

CREATE SEQUENCE schema.order_details_id_seq
    INCREMENT 1
    MINVALUE 1
    MAXVALUE 9223372036854775807
    START 37
    CACHE 1;

Models.

// Model
class Order extends AppModel {
public $useDbConfig = 'other_data';
public $hasMany = array(
    'OrderDetail' => array(
        'className' => 'OrderDetail',
        'foreignKey' => 'order_id',
        'dependent' => true,
        'order' => array(
                      'OrderDetail.order_id',
                      'OrderDetail.field_1'
                     ))
);

class OrderDetail extends AppModel {
public $useDbConfig = 'other_data';
public $belongsTo = array(
    'Order' => array(
        'className' => 'Order',
        'foreignKey' => 'order_id',
        'dependent'    => true
    ),

// model Order save code on recreation of order
$this->OrderDetail->deleteAll(array('OrderDetail.order_id' => $this->id));

At this point tried to insert $this->OrderDetail->query('VACUUM FULL ANALYZE order_details'); with no effect

foreach ($details as $d) {
    $this->OrderDetail->create();
    $this->OrderDetail->save($d /*array(
        'order_id' => $this->id,
        'field_1' => 1, 
        'field_2' => 2, 
        'field_3' => 'value'
      )*/);
}

I get error on first foreach loop.
Weirdest thing is that problem appears and disappears after some time randomly.

Any suggestions on what it could be and how to get rid of it?


Currently solved problem using code.

$this->Order->id = $id;
$this->Order->delete();

It fires 2 queries for each row (100 extra in my case!) of delete statements instead of two in case of

$this->OrderDetail->deleteAll(array('OrderDetail.order_id' => $id));

So for this time it has space for improvement.

EDIT: Currently code works as it should with tweaked DboSource.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:56:12+00:00Added an answer on June 12, 2026 at 5:56 pm

    It seems that cake was looking in public schema for sequence where it is not located.

    Fixed it by tweaking to include schema name in last insert getter inf file Model/Datasource/DboSource.php create method with this diff

    @@ -1006,7 +1006,7 @@

    if ($this->execute($this->renderStatement('create', $query))) {
        if (empty($id)) {
    -       $id = $this->lastInsertId($this->fullTableName($model, false, false), $model->primaryKey);
    +       $id = $this->lastInsertId($this->fullTableName($model, false, true), $model->primaryKey);
        }
        $model->setInsertID($id);
        $model->id = $id;
    

    I know that modifying core is not the way to go, but as long as it is working it is fine with me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After my previous problem, TortoiseSVN Can't Connect was resolved, I ran into a new
I've a problem deleting a row from a table view. Here is the code
This problem follows on from a previous question . When I run the following
I ran into this quite often stated problem but even after looking up nearly
My problem is as follows. I have an array of objects in the form
A minimal code that reproduces the problem is as follows: <div class=cell> <input type=text
Newbie here! My problem is as follows: I have a dynamically populating ul where
I'm facing a problem that I can summarize as it follows: I have a
I have a mysql problem, my query looks as follows but not complete SELECT
Right now i'm having a problem with sitecore workflow. The issue is as follows:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.