Rollback in specific table Laravel 4

Asked

Viewed 395 times

5

I am manipulating a Mysql database with Laravel 4. I want to know if there is any way to do a rollback in just one of the database tables. For example, my Migration included the tables x, y and z. I want to do a rollback only in table y. It is possible?

  • Hi @Amanda Lima, your question wouldn’t be about truncate? because the answer to that question was about truncate. If that’s the case, I’d like to edit your question. When you run a Rollback it undoes only the executed action in momenta, the truncate clears the entire table.

  • Really @Miguelbatista. I don’t know if she’s referring to the method down, present in the migration classes of Laravel. But, if to analyze by the date answer, I think it has nothing to do with rollback. But remember, if you’re talking about the method down from Migrations, so that’s right.

1 answer

4


Yes it is possible:

To delete table data:

DB::table('tabela_y')->delete();

Truncating in a table:

DB::table('tabela_y')->truncate();

Link of documentation.

  • Thanks, I hadn’t thought of it that way! There’s some way to do it by Artisan?

  • 1

    Well you can try to give one php artisan tinker and put the command I posted. I don’t think you have a direct command for this.

  • Thank you again!

  • "Delete table" or "Delete table data"?

  • Delete table data, fix answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.