Tag

Migrations

Browsing

Today, We are going to learn Laravel Migration add new column to an existing table.  In the last Laravel Migration tutorial, We learn How to create the database table using Laravel Migrations. In this tutorial, We are going to learn How to add a new column to an existing table. Many times we need an extra column after the table has been created using Laravel migrations. Let’s see how we can manage migration files for adding the extra column to the database table.

Today, We are going to add the column for an image on the blog table. First, follow this tutorial for creating the blog table. After, creating the blog table let’s see how we can add the new column to existing blog table.

Laravel Migration add new column

First of all, We are going to create the migration file to add a new column to existing database table. Let’s follow the command for creating the migration.

Finally, We are ready with the new migration file. The new migration will generate into database/migrations directory. Let’s open the migration file and write the code to add an image column to an existing database table.

Finally, We are ready with the migration file. Now, let’s run the migration by following the command.

Finally, We add the new image column to a blog table. So, it’s too easy to add an extra column to an existing table using laravel migrations. Still, If you face any issue write the comment.

Today, We are going to learn Laravel Migrations to creating the new database table. We can manage version control for our database using Laravel Migrations. Migration is really helpful for managing database when we work with developer team. Laravel Migration allows your team to easily manage and share application database scheme. Migration is pair with Laravel database Schema builder to easily build your application database schema.

When We are working with a developer team then One of our team member require a new column to the table. When team member manually adds the column to the database table. At that time we need to share database schema with all team member and it’s hard to manage database. Laravel Migrations solve that problem now we can easily share the database scheme with team member. We just need to create the migration for adding the new column then follow the artisan migrate command for update the database schema.

Laravel Migrations

We are going to learn How to create the table using Laravel Migrations and generate the database table schema. So, First of all, we are going to create migration file by following artisan command.

I hope you install Laravel If not yet just follow this tutorial.

The new migration will generate into database/migrations directory. Each migration file name contains a timestamp which allows Laravel to determine the order of the migrations. Open the Migration file and create the columns for a table like

Finally, We are ready with the first Laravel Migration file. We cover the all basic column data types for more detail visit migration document here. Now let’s run the migration file by following the artisan command

It’s too easy to manage database tables using Laravel Migrations. We just need to create the migration file then run the migration using artisan command.