3

I created the migration file:

public function up()
{
    //
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    //
}

I usually used this to creating tables or alter them . Is there a way to run an update query, something like:

UPDATE `mytable` SET `column` = 'test' WHERE `column` != 'test2'; 

and also the reverse of it. How can I do that?

Thank you!

[UPDATE] I followed this post: Run raw SQL in migration , but there is no indication where should I add this update query or how to reverse it . Its about just altering a table

Attila Naghi
  • 2,535
  • 6
  • 37
  • 59
  • @FMK srry but there is no indication where should i include that code and it is about altering tables , not updating , also there is no mention at all how to reverse it . Thank you – Attila Naghi Mar 15 '18 at 10:16
  • @u_mulder , please see my update why it is not a duplicate . Thank you – Attila Naghi Mar 15 '18 at 10:18
  • Read __my__ duplicate, __please__. There're only __two__ places where you can put your code - `up` or `down` function. Thank you. – u_mulder Mar 15 '18 at 10:20
  • 1
    I managed to update it with `DB::statement("UPDATE `mytable` SET `column` = 'test' WHERE `column` != 'test2'");` . The `DB::raw` doesn't work as suggested in the duplicates. But I still cannot find a way how to reverse it in the `down` method :( – Attila Naghi Mar 15 '18 at 10:40

0 Answers0