久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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)
主站蜘蛛池模板: 精品久久九 | 国产免费色 | jizz在线免费观看 | 草久网 | 国产色| caoporn免费在线视频 | 精品在线观看一区 | 久久亚洲国产精品日日av夜夜 | 国产精品久久久久久中文字 | 日本一区二区高清视频 | 91干b| 亚洲第一在线 | 欧美视频在线看 | 亚洲精品无 | 亚洲一区二区三区视频在线 | 久久99视频免费观看 | 第一av | 色性av | 国产蜜臀97一区二区三区 | www.中文字幕 | 中文字字幕在线中文乱码范文 | 国产精品亚洲视频 | 日韩a在线 | 91极品尤物在线播放国产 | 国产亚洲精品综合一区 | 啪啪免费网站 | 久久av一区二区三区 | 欧美老妇交乱视频 | av中文字幕网站 | 天堂av中文 | 免费中文字幕 | 黄色网址免费看 | 精品一区二区三区91 | 精品日本久久久久久久久久 | 中日韩毛片 | 啪啪免费网站 | 日韩国产在线观看 | 在线a视频网站 | 97色免费视频 | 欧美亚洲国产日韩 | 看片一区|