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
1 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)
1 UseThink\migration\migrator;2 UseThink\migration\db\column;3 4 classCreateusertableextendsMigrator5 {6 7 /**8 * Create user table9 */Ten Public functionUp () { One $table=$this->table (' user '); A $table->addcolumn (' username ', ' string ', [' limit ' = = 30]) -->addcolumn (' Passwork ', ' string ', [' limit ' = = 32]) -->addcolumn (' email ', ' string ', [' limit ' = = 25]) the->addcolumn (' Lastlogin_ip ', ' string ', [' limit ' = = 15]) -->addtimestamps (' Create_time ', ' lastlogin_time ') -->addcolumn (' status ', ' Integer ', [' limit ' = = 1, ' default ' = + 1]) -->setid (' user_id ') +-save (); - } + A /** at * Provides rollback of the Delete user table method - */ - Public functionDown () { - $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.
TP5 Migrate Database Migration Tool