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-migration
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'); } }
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!