pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

Laravel 遷移是如何工作的?

How do Laravel migrations work?(Laravel 遷移是如何工作的?)
本文介紹了Laravel 遷移是如何工作的?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我對這種類型的框架完全陌生.我來自準系統 PHP 開發,我似乎找不到一個易于理解的指南,遷移實際上做了什么.

I'm totally new to this type of framework. I've come from barebones PHP development and I can't seem to find an easy to understand guide what migrations actually do.

我正在嘗試創建一個已有數據庫的項目.我用過這個:https://github.com/Xethron/migrations-generator[1] 但通過遷移對架構進行更改似乎會吐出錯誤,這意味著我不知道自己在做什么.

I'm trying to create a project that already has an existing database. I've used this: https://github.com/Xethron/migrations-generator[1] but making changes to the schema via the migrations seems to spit out errors which means I have no idea what I'm doing.

我真的需要簡單介紹一下遷移的實際作用、它們如何影響數據庫以及您認為對絕對初學者有幫助的其他任何事情.

I really need a simple run down of what migrations actually do, how they affect the database and anything else you think would help an absolute beginner.

推薦答案

遷移是數據庫的一種版本控制.它們允許團隊修改數據庫架構并保持最新的當前架構狀態.遷移通常與 Schema Builder 配對,以輕松管理應用程序的架構.

Migrations are a type of version control for your database. They allow a team to modify the database schema and stay up to date on the current schema state. Migrations are typically paired with the Schema Builder to easily manage your application's schema.

通過遷移,您不需要在 phpMyAdmin 中創建表,您可以在 Laravel 中完成.以下是創建用戶表的示例:

With migrations you don't need to create table in phpMyAdmin, you can do it in Laravel. Here is an example to create a user table:

class CreateUsersTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function(Blueprint $table)
        {
            $table->increments('id'); // autoincrement id field
            $table->string('name');   // string field
            $table->string('lastname');
            $table->string('title');
            $table->string('email')->unique();   // unique string field
            $table->string('password', 60);      // string field with max 60 characters
            $table->boolean('Status')->default(0); // string field with default value 0
            $table->timestamps();

        });
    }


    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('users');
    }

}

在這段代碼中,我們創建了包含姓名"、姓氏"等字段的表……我們在 Laravel 代碼中說過,當遷移完成時,它們是字符串類型,我們在數據庫中有包含這些字段的完整表.

I this code we create table with fields like "name", "lastname"... we said in our Laravel code they are string type when migration is done we have complete table in databese with this fields.

運行遷移以創建表

要創建遷移,您可以在 Artisan CLI(artisan 命令行界面)上使用 make:migration 命令:

To create a migration, you may use the make:migration command on the Artisan CLI (artisan command line interface):

php artisan make:migration create_users_table

php artisan make:migration create_users_table --create=users

運行遷移以更改表

當你需要在數據庫表中做一些改變的例子:向用戶表添加字段投票時,你可以在你的 Laravel 代碼中這樣做,而無需接觸 SQL 代碼

When you need to do some changes in database table example: add field vote to user table you can do like this in your Laravel code without touching SQL code

php artisan make:migration add_votes_to_users_table --table=users

回滾上次遷移操作

如果你犯了錯誤并且做錯了什么,你總是可以回滾到以前狀態的數據庫.

If you make mistake and did something wrong you can always rollback to return database in previous state.

php artisan migrate:rollback

回滾所有遷移

php artisan migrate:reset

回滾所有遷移并再次運行它們

php artisan migrate:refresh

php artisan migrate:refresh --seed

遷移的最大優勢之一是在不接觸 SQL 代碼的情況下創建數據庫.您可以在 PHP 代碼中創建具有關系的整個數據庫,然后將其遷移到 MySQL、PL/SQL、MSSQL 或任何其他數據庫中.

One of best advantage of migrations are creating database without touching SQL code. You can make whole database with relationship in PHP code then migrate it into MySQL, PL/SQL, MSSQL or any other database.

另外我推薦免費的 Laravel 5 基礎系列,在劇集中7 您可以了解更多有關遷移的信息.

Also I recommend the free Laravel 5 fundamental series, in episode 7 you can hear more about migrations.

這篇關于Laravel 遷移是如何工作的?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Magento products by categories(按類別劃分的 Magento 產品)
Resource interpreted as image but transferred with MIME type text/html - Magento(資源被解釋為圖像但使用 MIME 類型 text/html 傳輸 - Magento)
Is there an event for customer account registration in Magento?(Magento 中是否有客戶帳戶注冊事件?)
Magento addFieldToFilter: Two fields, match as OR, not AND(Magento addFieldToFilter:兩個字段,匹配為 OR,而不是 AND)
quot;Error 404 Not Foundquot; in Magento Admin Login Page(“未找到錯誤 404在 Magento 管理員登錄頁面)
Get Order Increment Id in Magento(在 Magento 中獲取訂單增量 ID)
主站蜘蛛池模板: 彼得逊采泥器-定深式采泥器-电动土壤采样器-土壤样品风干机-常州索奥仪器制造有限公司 | 高低温试验房-深圳高低温湿热箱-小型高低温冲击试验箱-爱佩试验设备 | 蜜蜂职场文库_职场求职面试实用的范文资料大全 | 「安徽双凯」自动售货机-无人售货机-成人用品-自动饮料食品零食售货机 | 浴室柜-浴室镜厂家-YINAISI · 意大利设计师品牌 | 咿耐斯 |-浙江台州市丰源卫浴有限公司 | TTCMS自助建站_网站建设_自助建站_免费网站_免费建站_天天向上旗下品牌 | 直读光谱仪,光谱分析仪,手持式光谱仪,碳硫分析仪,创想仪器官网 | 浙江寺庙设计-杭州寺院设计-宁波寺庙规划_汉匠 | 武汉创亿电气设备有限公司_电力检测设备生产厂家| 物流公司电话|附近物流公司电话上门取货| 不锈钢酒柜|恒温酒柜|酒柜定制|酒窖定制-上海啸瑞实业有限公司 | 10吨无线拉力计-2吨拉力计价格-上海佳宜电子科技有限公司 | 石家庄小程序开发_小程序开发公司_APP开发_网站制作-石家庄乘航网络科技有限公司 | 软文推广发布平台_新闻稿件自助发布_媒体邀约-澜媒宝 | 餐饮小吃技术培训-火锅串串香培训「何小胖培训」_成都点石成金[官网] | 网络推广公司_网络营销方案策划_企业网络推广外包平台-上海澜推网络 | 苏州注册公司_苏州代理记账_苏州工商注册_苏州代办公司-恒佳财税 | 厂房出租_厂房出售_产业园区招商_工业地产 - 中工招商网 | 协议书_协议合同格式模板范本大全 | 植筋胶-粘钢胶-碳纤维布-碳纤维板-环氧砂浆-加固材料生产厂家-上海巧力建筑科技有限公司 | 中山东港家具集团-酒店-办公-医养家具定制厂家 | 衬氟止回阀_衬氟闸阀_衬氟三通球阀_衬四氟阀门_衬氟阀门厂-浙江利尔多阀门有限公司 | 泰州物流公司_泰州货运公司_泰州物流专线-东鑫物流公司 | 艾默生变频器,艾默生ct,变频器,ct驱动器,广州艾默生变频器,供水专用变频器,风机变频器,电梯变频器,艾默生变频器代理-广州市盟雄贸易有限公司官方网站-艾默生变频器应用解决方案服务商 | 搜活动房网—活动房_集装箱活动房_集成房屋_活动房屋 | 广东机电安装工程_中央空调工程_东莞装饰装修-广东粤标建设有限公司 | 英国公司注册-新加坡公司注册-香港公司开户-离岸公司账户-杭州商标注册-杭州优创企业 | 深圳办公室装修,办公楼/写字楼装修设计,一级资质 - ADD写艺 | 网站制作优化_网站SEO推广解决方案-无锡首宸信息科技公司 | 粉末冶金-粉末冶金齿轮-粉末冶金零件厂家-东莞市正朗精密金属零件有限公司 | 工装定制/做厂家/公司_工装订做/制价格/费用-北京圣达信工装 | 山东钢格板|栅格板生产厂家供应商-日照森亿钢格板有限公司 | 沈阳真空机_沈阳真空包装机_沈阳大米真空包装机-沈阳海鹞真空包装机械有限公司 | 新型游乐设备,360大摆锤游乐设备「诚信厂家」-山东方鑫游乐设备 新能源汽车电池软连接,铜铝复合膜柔性连接,电力母排-容发智能科技(无锡)有限公司 | 深圳成考网-深圳成人高考报名网 深圳工程师职称评定条件及流程_深圳职称评审_职称评审-职称网 | 广东泵阀展|阀门展-广东国际泵管阀展览会 | 金刚网,金刚网窗纱,不锈钢网,金刚网厂家- 河北萨邦丝网制品有限公司 | 精密线材测试仪-电线电缆检测仪-苏州欣硕电子科技有限公司 | 上海瑶恒实业有限公司|消防泵泵|离心泵|官网 | 台湾HIWIN上银直线模组|导轨滑块|TBI滚珠丝杆丝杠-深圳汉工 | QQ房产导航-免费收录优秀房地产网站_房地产信息网 |