laravel 如何删除laravel 5中的表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37275551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to delete table in laravel 5?
提问by fansz
I have a probleme to delete a table in mysql with Laravel 5.
我在使用 Laravel 5 删除 mysql 中的表时遇到问题。
How delete table in laravel 5 ?
如何在 Laravel 5 中删除表?
Not truncate table :
不截断表:
回答by Alexey Mezenin
You can run php artisan migrate:rollback
command and if a table was created in a last batch, it will be deleted (if down()
method of a migration was written correctly, of course).
您可以运行php artisan migrate:rollback
命令,如果表是在最后一批中创建的,它将被删除(当然,如果down()
迁移方法编写正确)。
If not, you can create a new migration and delete table with drop()
method:
如果没有,您可以使用以下drop()
方法创建一个新的迁移和删除表:
Schema::drop('users');
Or:
或者:
Schema::dropIfExists('users');
回答by Sanzeeb Aryal
To delete records from the table:
要从表中删除记录:
DB::table('table_name')->delete();
DB::table('table_name')->delete();
If you wish to truncate the entire table, which will remove all rows and reset the auto-incrementing ID to zero, you may use the truncate method:
如果您希望截断整个表,这将删除所有行并将自动递增 ID 重置为零,您可以使用 truncate 方法:
DB::table('table_name')->truncate();
DB::table('table_name')->truncate();
回答by Vikash
By fetching the DB instance via table name.
通过表名获取数据库实例。
DB::table('table_name')->delete();
回答by Momen Zaqout
Schema::dropIfExists('users');
回答by kumar
find the id of a row then perform an action
找到一行的 id 然后执行一个动作
$obj=obj::find($id);
$obj=obj::find($id);
$obj->delete();
$obj->delete();