<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之旅 廣告
                ### 討論 為什么使用遷移文件來創建數據庫? 1. 對數據庫的變更操作有日志記錄。 2. 便于生成一對多和多對多結構的數據庫。 ### 新建數據庫 >[info] 請參考 http://www.yiiframework.com/doc-2.0/guide-db-migrations.html 1. 編寫數據庫遷移文件 2. 應用遷移文件,創建數據庫 3. 生成Model ### 案例:Restaurant & Review ~~~ # 添加Restaurant表 yii migrate/create create_restaurant $this->createTable('restaurant', [ 'id' => $this->primaryKey(), 'name' => $this->string(), 'city' => $this->string(), 'province' => $this->string() ]); yii migrate # 添加Review表 yii migrate/create create_review $this->createTable('review', [ 'id' => $this->primaryKey(), 'rating' => $this->integer(), 'body' => $this->text() ]); $this->addColumn('review', 'restaurant_id', $this->integer()); $this->createIndex('idx-review-restaurant_id', 'review', 'restaurant_id'); $this->addForeignKey('fk-review-restaurant_id', 'review', 'restaurant_id', 'restaurant', 'id', 'CASCADE'); yii migrate # 生成Model yii gii/model --tableName=restaurant --modelClass=Restaurant --ns=common\models yii gii/model --tableName=review --modelClass=Review --ns=common\models ~~~ ### 添加初始數據 1. 通過phpMyAdmin 2. 通過程序方式 ~~~ yii migrate/create seed_restaurant_review $restaurant = new Restaurant(); $restaurant->name = "老鄉雞"; $restaurant->city = '合肥'; $restaurant->province = '安徽省'; $restaurant->save(); $review = new Review(); $review->rating = 9; $review->body = '真是美味的快餐'; $review->restaurant_id = $restaurant->id; $review->save(); $review = new Review(); $review->rating = 6; $review->body = '隨便吃吃'; $review->restaurant_id = $restaurant->id; $review->save(); yii migrate ~~~ ### 添加字段 ~~~ yii migrate/create add_reviewer_to_review --fields="reviewer_name:string" $this->addColumn('review', 'reviewer_name', $this->string()); yii migrate ~~~ ### 修改字段 ~~~ yii migrate/create alter_reviewer_to_review $this->alterColumn('review', 'reviewer_name', $this->string(100)); yii migrate ~~~
                  <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>

                              哎呀哎呀视频在线观看