Home >Backend Development >PHP Tutorial >Detailed explanation of database migration using thinkphp5 migrate
This time I will bring you a detailed explanation of the use of thinkphp5 migrate database migration. What are the precautions when using thinkphp5 migrate database migration. The following is a practical case, let's take a look.
tp5 is very different from tp3.2
migrate is one of them. Through migrate, programmers can create a database in php code #Modify rollback and other operations
First download the migrate extension, and execute the command line in the current project directorycomposer require topthink/think-migrationYou can check whether migrate is successfully downloaded by using the php think command
use think\migration\Migrator; use think\migration\db\Column; class CreateUserTable extends Migrator { /** * 建立用户表 */ public function up(){ $table = $this->table('user'); $table->addColumn('username' , 'string' , ['limit' => 30]) ->addColumn('passwork' , 'string' , ['limit' => 32]) ->addColumn('email' , 'string' , ['limit' => 25]) ->addColumn('lastlogin_ip' , 'string' , ['limit' => 15]) ->addTimestamps('create_time' , 'lastlogin_time') ->addColumn('status' , 'integer' , ['limit' => 1 , 'default' => 1]) ->setId('user_id') ->save(); } /** * 提供回滚的删除用户表方法 */ public function down(){ $this->dropTable('user'); } }Some of the above methods , I didn’t see the official document. What I read online was what Xiao Teng explained. Using migrate: run will execute all the migrate up methods. You can use migrate: rollback. Roll back the last executed migrate file (with -t 0 parameter to roll back all) You can view the current migration execution status through migrate: statusAfter executing the run method, the user table is successfully created
Detailed explanation of the steps for Laravel to use Redis to share Session
Detailed explanation of the steps for Laravel to implement password reset
The above is the detailed content of Detailed explanation of database migration using thinkphp5 migrate. For more information, please follow other related articles on the PHP Chinese website!