Метод 1: использование необработанного запроса к базе данных
Вы можете использовать необработанный запрос к базе данных, чтобы изменить целочисленный столбец на двойной столбец. Вот пример:
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ModifyColumnToDoubleMigration extends Migration
{
/
* Run the migrations.
*
* @return void
*/
public function up()
{
// Alter the table to modify the column to a double
DB::statement('ALTER TABLE your_table MODIFY your_column DOUBLE');
}
/
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// Revert the column modification if needed
DB::statement('ALTER TABLE your_table MODIFY your_column INTEGER');
}
}
Метод 2: использование построителя схем Laravel
Вы также можете использовать построитель схем Laravel для изменения типа столбца. Вот пример:
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ModifyColumnToDoubleMigration extends Migration
{
/
* Run the migrations.
*
* @return void
*/
public function up()
{
// Alter the table to modify the column to a double
Schema::table('your_table', function (Blueprint $table) {
$table->double('your_column')->change();
});
}
/
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// Revert the column modification if needed
Schema::table('your_table', function (Blueprint $table) {
$table->integer('your_column')->change();
});
}
}