THINKPHP5 Migrate Database migration using detailed

Source: Internet
Author: User
This time to bring you THINKPHP5 migrate database migration use detailed, THINKPHP5 migrate database migration Use of considerations, the following is the actual case, together to see.

TP5 is quite different from tp3.2.

Migrate is one of the things that can be done by migrate programmers to create DATABASE modification rollback in PHP code

First download the Migrate extension, the command line to the current project directory execution

Composer require topthink/think-migration

You can see if migrate downloaded successfully by using the PHP think command

Generate migrate file under database using Migrate:create Migrate file name (hump method with first capitalization)

It is possible to establish a failure prompt without any method generally composer gets the TP version too low, consider modifying the version of migrate in the Composer.json file to 1.* or ^1.0

Re-composer Update

Configure the database in the database.php under Application

The following is a copy of the contents of the Migrate file (after creation there is a default method change (), delete it)

Use Think\migration\migrator; Use Think\migration\db\column; Class Createusertable extends Migrator {   /**   * Build User table   *   /Public Function up () {     $table = $this Table (' user ');     $table->addcolumn (' username ', ' string ', [' limit ' = =])        ->addcolumn (' passwork ', ' string ', [' Limit ' => ; ]        ->addcolumn (' email ', ' string ', [' limit '])        ->addcolumn (' lastlogin_ip ', ' string ', [' limit ') =        []->addtimestamps (' create_time ', ' lastlogin_time ')        ->addcolumn (' status ', ' Integer ', [' Limit ' = 1, ' default ' = 1])        ->setid (' user_id ')        ->save ();   }   /**   * Provides rollback of the Delete user table method   *   /Public Function down () {     $this->droptable (' user ');}   }

Some of the above methods, the official documents I did not see where, on the internet I read the little Teng explained

Using Migrate:run will perform all the migrate up methods

Migrate:rollback can roll back the previous executed migrate file (with the-T 0 parameter rollback ALL)

Migrate:status to view current migrate execution

The user table was successfully established after the Run method was executed

It's very convenient.

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

Laravel using Redis to share session steps

Laravel Implementing password Reset steps

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.