Solution and explanation
- Migrations are version-controlled database schema definitions.
php artisan make:migration create_products_table
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->decimal('price', 10, 2);
$table->timestamps();
});
php artisan migrate
php artisan migrate:rollback
php artisan migrate:refresh
php artisan migrate:fresh
rollback undoes the latest migration batch. refresh rolls back every migration and runs them again. fresh drops all tables and migrates from scratch.
- Warning: refresh and fresh delete data.
- Never run them against production or a shared database; use new forward-only migrations there.