Friday, October 5, 2018

Database: Migrations

  1. Introduction:
    • Migrations are like version control for your database, allowing your team to easily modify and share the application's database schema.
    • The Laravel Schema facade provides database agnostic support for creating and manipulating tables across all of Laravel's supported database systems.
  2. Generating Migrations
    1. Create a migration:
  • php artisan make:migration create_users_table 
             Ex: The --table and --create options may also be used to indicate the name of the table and whether the migration will be creating a new table.
php artisan make:migration create_users_table --create=users

php artisan make:migration add_votes_to_users_table --table=users
         
  1. Migrations Structure
    1. A migration class contains two methods: up and down. The up method is used to add new tables, columns, or indexes to your database, while the down method should reverse the operations performed by the up method.
  2. Running Migrations
    1. To run all of your outstanding migrations, execute the migrate Artisan command:
    • php artisan migrate
  1. Rollback Migrations
  2. Tables
  3. Column
  4. Indexs

No comments:

Post a Comment