Here is the TP5 Migrate Database Migration Tool related to the introduction, very simple and practical, the need for small partners to see the example of this article
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.
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!