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

Laravel 遷移是如何工作的?

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

問(wèn)題描述

我對(duì)這種類(lèi)型的框架完全陌生.我來(lái)自準(zhǔn)系統(tǒng) PHP 開(kāi)發(fā),我似乎找不到一個(gè)易于理解的指南,遷移實(shí)際上做了什么.

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.

我正在嘗試創(chuàng)建一個(gè)已有數(shù)據(jù)庫(kù)的項(xiàng)目.我用過(guò)這個(gè):https://github.com/Xethron/migrations-generator[1] 但通過(guò)遷移對(duì)架構(gòu)進(jìn)行更改似乎會(huì)吐出錯(cuò)誤,這意味著我不知道自己在做什么.

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.

我真的需要簡(jiǎn)單介紹一下遷移的實(shí)際作用、它們?nèi)绾斡绊憯?shù)據(jù)庫(kù)以及您認(rèn)為對(duì)絕對(duì)初學(xué)者有幫助的其他任何事情.

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.

推薦答案

遷移是數(shù)據(jù)庫(kù)的一種版本控制.它們?cè)试S團(tuán)隊(duì)修改數(shù)據(jù)庫(kù)架構(gòu)并保持最新的當(dāng)前架構(gòu)狀態(tài).遷移通常與 Schema Builder 配對(duì),以輕松管理應(yīng)用程序的架構(gòu).

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.

通過(guò)遷移,您不需要在 phpMyAdmin 中創(chuàng)建表,您可以在 Laravel 中完成.以下是創(chuàng)建用戶(hù)表的示例:

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');
    }

}

在這段代碼中,我們創(chuàng)建了包含姓名"、姓氏"等字段的表……我們?cè)?Laravel 代碼中說(shuō)過(guò),當(dāng)遷移完成時(shí),它們是字符串類(lèi)型,我們?cè)跀?shù)據(jù)庫(kù)中有包含這些字段的完整表.

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.

運(yùn)行遷移以創(chuàng)建表

要?jiǎng)?chuàng)建遷移,您可以在 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

運(yùn)行遷移以更改表

當(dāng)你需要在數(shù)據(jù)庫(kù)表中做一些改變的例子:向用戶(hù)表添加字段投票時(shí),你可以在你的 Laravel 代碼中這樣做,而無(wú)需接觸 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

回滾上次遷移操作

如果你犯了錯(cuò)誤并且做錯(cuò)了什么,你總是可以回滾到以前狀態(tài)的數(shù)據(jù)庫(kù).

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

回滾所有遷移并再次運(yùn)行它們

php artisan migrate:refresh

php artisan migrate:refresh --seed

遷移的最大優(yōu)勢(shì)之一是在不接觸 SQL 代碼的情況下創(chuàng)建數(shù)據(jù)庫(kù).您可以在 PHP 代碼中創(chuàng)建具有關(guān)系的整個(gè)數(shù)據(jù)庫(kù),然后將其遷移到 MySQL、PL/SQL、MSSQL 或任何其他數(shù)據(jù)庫(kù)中.

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.

另外我推薦免費(fèi)的 Laravel 5 基礎(chǔ)系列,在劇集中7 您可以了解更多有關(guān)遷移的信息.

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

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

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

相關(guān)文檔推薦

Magento products by categories(按類(lèi)別劃分的 Magento 產(chǎn)品)
Resource interpreted as image but transferred with MIME type text/html - Magento(資源被解釋為圖像但使用 MIME 類(lèi)型 text/html 傳輸 - Magento)
Is there an event for customer account registration in Magento?(Magento 中是否有客戶(hù)帳戶(hù)注冊(cè)事件?)
Magento addFieldToFilter: Two fields, match as OR, not AND(Magento addFieldToFilter:兩個(gè)字段,匹配為 OR,而不是 AND)
quot;Error 404 Not Foundquot; in Magento Admin Login Page(“未找到錯(cuò)誤 404在 Magento 管理員登錄頁(yè)面)
Get Order Increment Id in Magento(在 Magento 中獲取訂單增量 ID)
主站蜘蛛池模板: 欧美做受喷浆在线观看 | 999热视频 | 91欧美激情一区二区三区成人 | 特级丰满少妇一级aaaa爱毛片 | 瑟瑟视频在线观看 | 欧美午夜视频 | 日本国产在线观看 | 成人黄色在线视频 | 国产午夜免费 | 亚洲高清在线视频 | 午夜欧美| 中文字幕超清在线观看 | 亚洲精品一区二区三区在线观看 | 美女扒开腿让人桶爽原神 | 国产视频一| 国产三级视频在线播放 | 久草中文在线 | www.av在线播放 | 久久av一区二区三区亚洲 | 一级免费毛片 | 亚洲高清在线观看 | wwwxxx欧美| www.国产精品| 四虎网站| 青青草免费在线 | 国产中文字幕在线播放 | 人与拘一级a毛片 | 天天干干干 | 夜夜操夜夜 | 国产午夜免费视频 | 午夜看片 | 丁香色婷婷 | 国产精品一区二区三 | 国产精品一区二区在线 | 久久手机免费视频 | 亚洲一区二区三区中文字幕 | 免费在线观看毛片 | 成人爽a毛片一区二区免费 亚洲午夜在线观看 | 亚洲免费视频一区 | 高潮毛片又色又爽免费 | 毛片tv |