Execute multiple laravel alter table migration queries in one?

旧街凉风 提交于 2021-01-27 17:07:18

问题


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

For example:

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

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


回答1:


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

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

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;');
});


来源:https://stackoverflow.com/questions/44200696/execute-multiple-laravel-alter-table-migration-queries-in-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!