Part of the EllisLab Network
   
 
CI 1.6.1 Postgre driver, cannot truncate a table referenced in a foreign key constraint
Posted: 06 May 2008 01:00 PM   [ Ignore ]  
Summer Student
Total Posts:  5
Joined  04-17-2008

It is not a reall bug.

I have got 2 tables:

CREATE TABLE table1 (
  
myid serial NOT NULL PRIMARY KEY
);

CREATE TABLE table2 (
  
myid int NOT NULL REFERENCES table1(myid) MATCH SIMPLE
      ON UPDATE CASCADE ON DELETE CASCADE
,
);

Lets suppose table2 is empty, and we try to truncate table1. This is what we get:

ERROR: cannot truncate a table referenced in a foreign key constraint

Method truncate from CI_DB_postgre_driver:

function _truncate($table)
{
        
return "TRUNCATE ".$this->_escape_table($table);
}

Should/could be:

function _truncate($table)
{
        
return "TRUNCATE ".$this->_escape_table($table)." CASCADE"; // HERE!
}

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 61065 Total Logged-in Users: 22
Total Topics: 73887 Total Anonymous Users: 2
Total Replies: 398536 Total Guests: 344
Total Posts: 472423    
Members ( View Memberlist )