Laravel Migration

What are Migrations?

  • Migrations in Laravel are version control for your database schema.
  • They allow you to create, modify, and delete tables & columns using PHP code instead of SQL queries.
  • They make database changes trackable, team-friendly, and reversible.

Why Use Migrations?

  • Database schema version control.
  • Share schema changes across teams.
  • Rollback changes if something breaks.
  • No need to write raw SQL.

Update .env

Update .env file variable for Database connection:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=my_app
DB_USERNAME=root
DB_PASSWORD=



Migration Types (Like Route Types)

Just like routes have multiple types, Migrations also have different operations.

  • Create Table Migration
  • Modify Table Migration

Migration Commands

Command

Description

php artisan make:migration create_users_table

Create a new migration file

php artisan migrate

Run all pending migrations

php artisan migrate:rollback

Rollback the last batch of migrations

php artisan migrate:reset

Rollback all migrations

php artisan migrate:refresh

Rollback & re-run all migrations

php artisan migrate:fresh

Drop all tables & re-run migrations

php artisan migrate:status

Show migration status (which are run / pending)

Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.