Skip to main content

Simple way implement migration in your site (Using Laravel 5.3)

Hi Everyone,
I want to share my migration experience (larvel 5.3) It’s to be good idea to implement in your site. If number of developers working in same script, no need of sharing your query changes to each to other. And also don’t worry about the table creation, fields changes in live server also. The single step will do this all the process for you. You just go to your folder path, hit the migrate command, it will do the all the changes will reflect in tables as well as field.

JUST, WE WILL GO SHORT TOUR WITH MIGRATION

HOW TO CREATE A TABLE USING MIGRATION:

           If you want to create a table using migration, write a make migration command. php artisan make:migration is syntax and create users table is a migration file name. You can give the migration file name what ever you want, for over understanding, i have created a migration file name as create_users_table
         Now, Please check your migration folder, you will get a new file with a create_users_table, some other prefix. You will see two predefied functions in this file, up() and down()

USE OF UP() FUNCTION IN MIGRATION FILE:

Common use of up function, you can able to create field for your table. What are fields you want to create table. You can write the field specification with character type like : Interger, string, enum, float, text

CREATE A FOREIGN FOR A TABLE:

There are two cases you will face, while creating a foreign. First one, you to create a field with foreign key. Second one, you want to create a foreign key for already created field

          FOREIGN KEY FOR WITH NEW FIELD CREATION: (AND ALSO YOU CAN ABLE TO CREATE DESIRED ACTION ONUPDATE, ONDELETE – (CASCADE, NO ACTION) )

          ADD A FOREIGN KEY FOR ALREADY CREATED FIELD: (IF THE FIELD IS ALREADY CREATED IN THIS TABLE MEANS, NO NEED TO CREATE AGAIN, WHEN YOUR ADDING A FOREIGN KEY)

USE OF DOWN() FUNCTION IN MIGRATION FILE:

The main purpose of down method in migration file is that, direct opposite of the up() function. There are number of cases will be there you want to write a correct functionality in down() function. Some of the scenario i have listed here,
  • If your created a table in up function, you want delete a table in down function
  • If your added foreign key in the up function, you want delete the foreign key in the down function
  • If your created a field with foreign key means, you want delete a field as well as key in the down function

WHEN DOWN() FUNCTION WILL BE USEFULL IN MIGRATION FILE:

It would be usefull, when your going for rollback. You just refer a migration table, you will batch id for the migration (like : 1,2,3)
Remove the last migration you just use:
Same as the rollback define by step, batch id 2 defined as first migration, batch id 3 defined as second migration. you want to rollback the first migration (batch id is 2). Do is this step

ROLLBACK ALL THE MIGRATION:

If you want to rollback all of your migration by just hit this command

ROLLBACK ALL THE MIGRATION AND DO THE MIGRATION BY SINGLE COMMAND:

This command will first rollback your all the changes, and the second migrate the table.

IF YOUR DOING ANY DELETION OR CREATION IN MIGRATION FOLDER OR  TABLE:

Based on the manual deletion and creation, if you face any error in the composer. While your migrating the table. YOU JUST DO IT, THIS COMMAND:

CREATING OR UPDATE, DELETE IN ALREADY EXISTING TABLE, BY CREATE A NEW MIGRATION FILE:

First you need to create a migration file by,
Now you will get a file in the migration folder with up(), down() function

Note : Best thing about creating migration schema, first create a parent table and then add a related foreign key for the table. It could be easy for you to understand the flow of the functionality

Comments

Popular posts from this blog

The requested URL /phpmyadmin was not found on this server. Apache/2.4.18 (Ubuntu) Server at localhost Port 80

Hi dudes, I'm getting Not Found error, when i hit a  http://localhost/phpmyadmin/ url, but i my system php, mysql & apache2 is already installed still i'm getting this error When i do this following step, the error get fixed. Do the following steps & Enjoy๐Ÿ˜ƒ๐Ÿ˜„๐Ÿ˜…๐Ÿ˜„๐Ÿ˜„๐Ÿ˜ƒ You need to configure your apache2.conf to make phpMyAdmin work. For more detail Please read  this section  in Ubuntu wiki. open a termianl and run gksu gedit /etc/apache2/apache2.conf Then add the following line to the end of the file. Include /etc/phpmyadmin/apache.conf Then restart apache /etc/init.d/apache2 restart

Install a node & npm specific versions using nvm (Node Version Manager)

Hi buddies, When i tried to install a node & npm in my system, i will be facing some problem with the version. I want to install a recent LTS (Long Term Support) Don't Do (If you want to install a specific version):  I don't know, how its gonna installed, but its not a recent Node LTS version sudo apt-get install nodejs-legacy sudo apt-get install npm Do (Using a NVM- Node Version Manager to install a specific version): Use the following command to install a NVM into your system $ curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash Reload the system environment using this command $ source ~/.profile $ source ~/.bashrc List all the nodejs version using this command $ nvm ls-remote Install a nodejs version, what ever you want (If you want to install multiple node version you can install using this command) $ nvm install 6.11.1 $ nvm install 8.2.1 List a node version using this command

PHP 7 with Laravel 5.3 installation problem ( Your requirements could not be resolved to an installable set of packages )

I'm Facing this problem, while installation using laravel 5.3 with PHP 7 Your requirements could not be resolved to an installable set of packages.   Problem 1     - phpunit/phpunit 5.5.5 requires ext-dom * -> the requested PHP extension dom is missing from your system.     - phpunit/phpunit 5.5.4 requires ext-dom * -> the requested PHP extension dom is missing from your system.     - phpunit/phpunit 5.5.3 requires ext-dom * -> the requested PHP extension dom is missing from your system.     - phpunit/phpunit 5.5.2 requires ext-dom * -> the requested PHP extension dom is missing from your system.     - phpunit/phpunit 5.5.1 requires ext-dom * -> the requested PHP extension dom is missing from your system.     - phpunit/phpunit 5.5.0 requires ext-dom * -> the requested PHP extension dom is missing from your system.     - phpunit/phpunit 5.4.8 requires ext-dom * -> the requested PHP extension dom is missing from your system.     - phpunit/phpunit 5.4.7 requir