Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Truncate Table using CakePHP?

I want to truncate my Database Table, with CakePHP Model, I have used $this->Model->deleteAll code for the same, and it works fine.

Now, What i want is, next time whenever my new records are inserting, it should start ID with 1 only, which does not work with deleteAll function, so Is there any default CakePHP Syntax to make table Truncate ?

Let me know !

like image 822
Aditya P Bhatt Avatar asked May 12 '11 05:05

Aditya P Bhatt


1 Answers

NOTE: This answer is valid only up to CakePHP 1.3. I haven't used this on the never versions so I've no idea whether it works.

deleteAll only deletes the data, it does not truncate the table.

You'll need to call the query() method.

$this->Model->query('TRUNCATE TABLE table_name_in_mysql;')

http://book.cakephp.org/view/1027/query

like image 72
JohnP Avatar answered Oct 20 '22 01:10

JohnP