Welcome Guest, Not a member yet? Register   Sign In
CI 1.6.1 Postgre driver, cannot truncate a table referenced in a foreign key constraint
#1

[eluser]piotrpolak[/eluser]
It is not a reall bug.

I have got 2 tables:

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

Code:
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:

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

Method truncate from CI_DB_postgre_driver:
Code:
function _truncate($table)
{
        return "TRUNCATE ".$this->_escape_table($table);
}

Should/could be:

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




Theme © iAndrew 2016 - Forum software by © MyBB