问题
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