* * @return void */ public function up() { // do the following steps in order: // 1- add a new column with the desired data type to the table // 2- fill the new column with the appropriate data // 3- delete the old column // 4- rename the new column to match name of ...
1php artisan make:migration create_flights_tableLaravel will use the name of the migration to attempt to guess the name of the table and whether or not the migration will be creating a new table. If Laravel is able to determine the table name from the migration name, Laravel will pre-...
$table->uuid('id');UUID equivalent column. $table->year('birth_year');YEAR equivalent column. Column Modifiers In addition to the column types listed above, there are several column "modifiers" you may use while adding a column to a database table. For example, to make the column "null...
你可以使用 make:migration Artisan command 生成数据库迁移。新的迁移将放在你的 database/migrations 目录每个迁移文件名都包含一个时间戳,允许 Laravel 确定迁移的顺序:php artisan make:migration create_flights_table Laravel 会根据迁移文件的名称确定表的名称已经是否在前一种创建新的数据表。
For example, this migration example creates a flights table:<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateFlightsTable extends Migration { /** * Run the migrations. * * @return void */ public ...
php artisan make:migration create_flights_tableLaravel 将使用迁移文件的名称来猜测表名以及迁移是否会创建一个新表。如果 Laravel 能够从迁移文件的名称中确定表的名称,它将在生成的迁移文件中预填入指定的表,或者,你也可以直接在迁移文件中手动指定表名。
useIlluminate\Database\DBAL\TimestampType;'dbal'=> ['types'=> ['timestamp'=> TimestampType::class, ], ], To change therolecolumn in thefund_userstable to anullable string with a maximum length of 50 characters, create a new migration and add the following within theup()method: ...
The new migration will be placed in yourdatabase/migrationsdirectory. Each migration file name contains a timestamp which allows Laravel to determine the order of the migrations. 新的迁移文件放在database/migrations目录下, 文件名包含时间戳记,在执行迁移时用来决定顺序。
Laravel Version: 10.3.3 PHP Version: 8.2.3 Database Driver & Version: MYSQL 8.0.32 doctrine/dbal Version: 3.6.1 Description: The column type change will not be made during a text column's migration to medium or long text. Keeping the col...
Database Indexing:Properly index your database tables to speed up data retrieval. Use the Schema facade to add indexes to your migration files. Schema::table('posts',function($table){ $table->index('column_name'); }); Database Transactions:Wrap database operations in transactions to ensure ...