Create migration for laravel for 898, 98.2
Assuming that you want to create a migration in Laravel for two different tables with the following column definitions:
Table 1:
Column 1: id (primary key)
Column 2: column_1 (integer)
Column 3: column_2 (float)
Table 2:
Column 1: id (primary key)
Column 2: column_1 (decimal)
Column 3: column_2 (string)
Here is how you can create the migration for these two tables:
Open your command prompt and navigate to your Laravel project directory.
Run the following command to create a new migration file for Table 1:
php artisan make:migration create_table_1 --create=table_1
- Open the migration file created in the "database/migrations" directory and update the "up" method with the following code:
public function up()
{
Schema::create('table_1', function (Blueprint $table) {
$table->id();
$table->integer('column_1');
$table->float('column_2');
$table->timestamps();
});
}
- Save the file and run the migration with the following command:
php artisan migrate
- Next, run the following command to create a new migration file for Table 2:
php artisan make:migration create_table_2 --create=table_2
- Open the migration file created in the "database/migrations" directory and update the "up" method with the following code:
public function up()
{
Schema::create('table_2', function (Blueprint $table) {
$table->id();
$table->decimal('column_1');
$table->string('column_2');
$table->timestamps();
});
}
- Save the file and run the migration with the following command:
php artisan migrate
Your Laravel project should now have two new tables with the specified column definitions.