Search code examples
cakephpcakephp-3.xcakephp-3.4phinx

CakePHP 3 Delete Row From Database using Migrations


I was taking a look at https://book.cakephp.org/3.0/en/migrations.html but I did not see anything about deleting a row from the database using Migrations...

How can I delete a row from a table using the migrations shell?


Solution

  • You can run queries with execute() in the migration files. There is no delete command per say but you can just run a snippet to delete the unwanted row. You should specify up() and down() vs change() in the migration as this is not a supported method in change.

    public function up()
    {
      $this->execute('DELETE FROM table_name WHERE conditions');
    }