<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] > [官方手冊](http://docs.phinx.org/en/latest/migrations.html#executing-queries) > [參考網址](https://www.jianshu.com/p/a01c5b6ea7f6) > [參考網址](http://www.bijishequ.com/detail/525120?p=) > migrations 就是通過php 的命令去生成和修改數據庫,甚至可以回退 ## 安裝 `composer require topthink/think-migration` ## 查看命令 ``` php thinkphp 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 seed //用于數據庫填充相關操作 seed:create Create a new database seeder seed:run Run database seeders ``` ## 使用`change`方法 遷移(生成數據表) ### 生成 1. 生成遷移類,類名必須使用 駝峰式 命名法, `$ php think migrate:create CreateUserTable` 2. 添加數據庫信息 ```php public function change() { $table = $this->table('users',array('engine'=>'MyISAM')); $table ->addColumn('username', 'string',array('limit' => 26,'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(); } ``` 3. 執行所有未執行的遷移類 `$ php think migrate:run` 執行某個遷移類 加 `-t`操作 `php think migrate:run -t YYYYMMDDHHMMSS //后面跟上遷移文件文件名的 時間戳部` ### 回滾 回滾遷移,默認只會回滾 最近一次 執行的遷移: `php think migrate:rollback` ` -t` 選項來指定需要回滾的遷移: `$ php think migrate:rollback -t YYYYMMDDHHMMSS` ## 刪除`change` 用而使用 `up`和`down`方法 刪除默認自帶的 change 方法,創建 up() 方法和 down() 方法。 up() 方法是在執行 run 命令執行的, down() 是在執行 rollback 命令執行的。 ``` public function up() { $table = $this->table('users'); $table->addColumn('nickname', 'string', ['limit' => 16, 'null' => false]) ->addColumn('email', 'string', ['limit' => 32, 'null' => false]) ->addColumn('password', 'string', ['limit' => 64, 'null' => false]) ->create(); } public function down() { $this->dropTable('users'); } ``` ## seed 方法生成數據 也可以用來生成非migrations生成的數據庫 生成 seen類 `php think seed:create User` 在類中創建數據 ``` public function run(){ public function run(){ $data = [ [ 'password' => $this->_pwd(), 'username' => date('Ymd H:i:s'), ], [ 'password' => $this->_pwd(), 'username' => date('Ymd H:i:s').'_1', ], ]; $posts = $this->table('users'); $posts->insert($data)->save(); } private function _pwd(){ return md5(rand(1111,9999)); } ``` 執行生成命令 `php think seed:run` 如果需要數據偽裝更好 可以用安裝第三方庫 `composer require fzaninotto/faker` ``` public function run() { $faker = Faker\Factory::create(); $data = []; for ($i = 0; $i < 100; $i++) { $data[] = [ 'username' => $faker->userName, 'password' => sha1($faker->password), 'password_salt' => sha1('foo'), 'email' => $faker->email, 'first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'created' => date('Y-m-d H:i:s'), ]; } $this->insert('users', $data); } ```
                  <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>

                              哎呀哎呀视频在线观看