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