<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 數據遷移 >[success]在這里以`ThinkPHP5.0`為例,在ThinkPHP5中提供了數據庫遷移工具`migration`。 > ## 1. 什么是`migration` >一種數據庫的版本控制,讓團隊在修改數據庫結構的同時,保持彼此的進度一致。幫你更簡單的管理數據庫。基于原生 thinkPHP 5.0 命令行工具,融入了 Phinx 的數據庫遷移 > >[danger]特別團隊協作開發時,這一功能非常方便。 > ## 2. `migration`的安裝 >使用`Composer` 進行安裝 > ~~~ composer require topthink/think-migration ~~~ >[danger]在安裝時一定要注意版本,如果您選擇的是ThinkPHP5.0那要么安裝的`migration`版本也應為1.*。如果您使的是ThinkPHP5.1,可以直接使用上述命令安裝最新版本即可。 > 1.* 版本的安裝 ~~~ composer require topthink/think-migration 1.* ~~~ ## 3. `migration`的使用 >安裝好后,即可以通過 `ThinkPHP`的命令行進行查看其相關的命令 > ~~~ php think ~~~ ~~~ Available commands: build Build Application Dirs clear Clear runtime file help Displays help for a command list Lists commands make make:controller Create a new resource controller class make:model Create a new model class migrate migrate:breakpoint Manage breakpoints migrate:create Create a new migration migrate:rollback Rollback the last or to a specific migration migrate:run Migrate the database migrate:status Show migration status optimize optimize:autoload Optimizes PSR0 and PSR4 packages to be loaded with classmaps too, good for production. optimize:config Build config and common file cache. optimize:route Build route cache. optimize:schema Build database schema cache. seed seed:create Create a new database seeder seed:run Run database seeders ~~~ >[dagner]這時命令中就多數了數據遷移相關的命令 > >[danger]### 使用前,要先配置數據庫(為空數據庫即可) ### 1. 創建遷移類 >創建遷移類,首字母必須為大寫 > ~~~ php think migrate:create Users ~~~ >[danger]`Users` 為表名稱(不含前輟) > >第一次執行的時候會確認是否創建遷移目錄; >確認之后; >這時會在項目根目錄下執行的該命令; >那么在項目跟目錄下會看到database/migrations/20170711153001_Users.php; >默認有一個change方法 遷移類實例 ~~~ <?php use Phinx\Migration\AbstractMigration; class Users extends AbstractMigration { /** * Change Method. */ public function change() { // create the table $table = $this->table('users',array('engine'=>'MyISAM')); $table->addColumn('username', 'string',array('limit' => 15,'default'=>'','comment'=>'用戶名,登陸使用')) ->addColumn('password', 'string',array('limit' => 32,'default'=>md5('123456'),'comment'=>'用戶密碼')) ->addColumn('login_status', 'boolean',array('limit' => 1,'default'=>0,'comment'=>'登陸狀態')) ->addColumn('login_code', 'string',array('limit' => 32,'default'=>0,'comment'=>'排他性登陸標識')) ->addColumn('last_login_ip', 'integer',array('limit' => 11,'default'=>0,'comment'=>'最后登錄IP')) ->addColumn('last_login_time', 'datetime',array('default'=>0,'comment'=>'最后登錄時間')) ->addColumn('is_delete', 'boolean',array('limit' => 1,'default'=>0,'comment'=>'刪除狀態,1已刪除')) ->addIndex(array('username'), array('unique' => true)) ->create(); } /** * Migrate Up. */ public function up() { } /** * Migrate Down. */ public function down() { } } ~~~ >[danger]注意:在設置數據表字段時會自動添加名為`id`的自增主鍵,如果想自定義自增主鍵的話,需要如下操作。 > ~~~php <?php public function change() { $table = $this->table('user',array('engine'=>'MyISAM')); $table->setId('user_id')->setPrimaryKey('user_id') ->addColumn('username', 'string',array('limit' => 15,'default'=>'','comment'=>'用戶名')) ->create(); } ?> ~~~ >[danger]注意:若不需要自增主鍵的話,請如下操作 ~~~ <?php public function change() { $table = $this->table('user',array('engine'=>'MyISAM')); $table->setId(false)->setPrimaryKey('user_id') ->addColumn('username', 'string',array('limit' => 15,'default'=>'','comment'=>'用戶名')) ->create(); } ?> ~~~ >[danger] #### 除了使用`change`方法操作之外,還可以使用`up`和`down`方法來創建。 ~~~ public function up () { $table = $this->table('user',array('engine'=>'MyISAM')); $table->setId('user_id') //關閉自動設置主鍵 ->setPrimaryKey('user_id') //設置主鍵 ->addColumn('username', 'string',array('limit' => 15,'default'=>'','comment'=>'用戶名')) ->create(); } public function down () { $this->dropTable('user'); ~~~ ### 2. 常用命令 #### 1.執行數據遷移( 創建數據表) ~~~ php think migrate:run ~~~ #### 2. 執行回滾(刪除重新操作) >[danger]調整表結構時需要執行,執行時會清空表中現在的數據 ~~~ php think migrate:rollback #回滾所有 php think migrate:rollback -t 0 ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看