一次执行多个laravel alter table迁移查询? [英] Execute multiple laravel alter table migration queries in one?

查看:113
本文介绍了一次执行多个laravel alter table迁移查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道是否有一种方法可以在一个查询中执行多个Laravel alter table迁移查询吗?

Does anybody know if there is a way to execute multiple Laravel alter table migration queries in one query?

例如:

Schema::table('table', function (Blueprint $table) {
    $table->integer('column 1');
    $table->integer('column 2');
});

这将创建两个ALTER表查询.除了编写SQL查询之外,是否有一种方法可以使它在一个查询中完成所有工作.

This would create two ALTER table queries. Is there a way to make it do all in one query, other than writing SQL query.

推荐答案

我意识到这个问题现在已经很老了,但是没有得到回答.

I realise this question is quite old now, but it wasn't answered.

我想说的是Laravel模式构建器更多是为了方便和跨平台兼容性,而不是性能.

I would say that the Laravel schema builder is more for convenience and cross platform compatibility, rather than for performance.

如果要优化 ALTER 查询,我建议使用 DB 门面并编写原始SQL.

If you want to optimise ALTER queries, I would suggest using the DB facade and writing raw SQL.

Schema::table('table', function (Blueprint $table) {
    DB::statement('ALTER TABLE table DROP COLUMN a, DROP COLUMN a;');
});

这篇关于一次执行多个laravel alter table迁移查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆