Tp5 migrate database migration tool, tp5migrate

Source: Internet
Author: User

Tp5 migrate database migration tool, tp5migrate

Tp5 is quite different from tp3.2.

Migrate is one of them. Through migrate, programmers can create database modification and rollback operations in php code.

First download the migrate extension and run the command line in the current project directory.

1 composer require topthink/think-migration

Use the php think command to check whether the migrate has been successfully downloaded.

Use migrate: create migrate file name (upper-case method) to generate a migrate file under the database

It is possible that the establishment fails. There is no way. Generally, the tp version obtained by composer is too low. consider modifying the migrate version in the composer. json file to 1. * or ^ 1.0.

Re-composer update.

Configure the database in database. php under application

The following is the content of one of the migrate files (there is a default method change () after creation, delete it)

1 use think \ migration \ Migrator; 2 use think \ migration \ db \ Column; 3 4 class CreateUserTable extends Migrator 5 {6 7/** 8 * create user table 9 */10 public function up () {11 $ table = $ this-> table ('user'); 12 $ table-> addColumn ('username', 'string', ['limit' => 30]) 13-> addColumn ('passwork', 'string', ['limit' => 32]) 14-> addColumn ('email ', 'string ', ['limit' => 25]) 15-> addColumn ('lastlogin _ ip', 'string', ['limit' => 15]) 16-> addTimestamps ('create _ time', 'lastlogin _ Time') 17-> addColumn ('status', 'integer', ['limit '=> 1, 'default' => 1]) 18-> setId ('user _ id') 19-> save (); 20} 21 22/** 23 * provides the rollback user table deletion method 24 */25 public function down () {26 $ this-> dropTable ('user '); 27} 28}

For some of the above methods, I did not see any official documents. I have explained it on the Internet.

Using migrate: run will execute all the up methods of migrate.

Migrate: rollback can be used to roll back the previous execution of the migrate file (with the-t 0 parameter rollback all)

You can use migrate: status to view the current migrate execution status.

After the run method is executed, the user table is successfully created.

Very convenient

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: info-contact@alibabacloud.com 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.