搜尋
首頁php框架Laravel五步驟搞定Laravel Migrations的使用

五步驟搞定Laravel Migrations的使用

Sep 01, 2021 pm 04:10 PM
laravelmigrationphp

本文由Laravel教學專欄給大家介紹,主要內容是“Laravel如何使用Migrations”,希望對需要的朋友有所幫助!

Laravel:使用Migrations

1、先利用artisan建立一個可遷移的資料表模板,該指令執行後會在database/migrations目錄下產生一個檔案

php artisan make:migration create_fees_count_table --create=fees_count

2、產生的檔案包含up和down兩個方法,其中up​​中是包含了新增表,新增列,加入索引等等一切的描述,down比較簡單,就是刪除表,當然裡面還可以有一些其他邏輯

3、up中支援的資料表列類型,做個備註,暫時不做翻譯

##$table->double('column', 15, 8);DOUBLE equivalent with precision, 15 digits in total and 8 after the decimal point.$table->enum('choices', ['foo', 'bar'] );ENUM equivalent for the database.$table->float('amount');FLOAT equivalent for the database. $table->increments('id');#Incrementing ID (primary key) using a "UNSIGNED INTEGER" equivalent.#$table->integer('votes');INTEGER equivalent for the database.$table->json(' options');JSON equivalent for the database.$table->jsonb('options');JSONB equivalent for the database.$table->longText('description');LONGTEXT equivalent for the database.# $table->mediumInteger('numbers');MEDIUMINT equivalent for the database.##$table->mediumText('description');$table->morphs('taggable');#Adds INTEGER taggable_id and STRING taggable_type.$table->nullableTimestamps();Same as timestamps(), except allows NULLs.$table-> ;rememberToken();Adds remember_token as VARCHAR(100) NULL.$table->smallInteger('votes'); SMALLINT equivalent for the database.##$table->softDeletes();$table->string('email');$table->string('name', 100); $table->text('description');$table->time('sunrise');##$table-> ;tinyInteger('numbers');TINYINT equivalent for the database.$table->timestamp('added_on');# TIMESTAMP equivalent for the database.$table->timestamps();Adds created_at and updated_at columns.
Command Description
$table->bigIncrements('id'); #Incrementing ID (primary key) using a "UNSIGNED BIG INTEGER" equivalent.
$table->bigInteger('votes'); BIGINT equivalent for the database.
$table->binary('data'); BLOB equivalent for the database.
$table->boolean(' confirmed'); BOOLEAN equivalent for the database.
$table->char('name', 4); CHAR equivalent with a length.
$table->date('created_at'); DATE equivalent for the database.
#$table->dateTime('created_at'); DATETIME equivalent for the database.
$table->decimal('amount', 5 , 2); DECIMAL equivalent with a precision and scale.
MEDIUMTEXT equivalent for the database.
Adds INTEGER taggable_id and STRING taggable_type.
Adds deleted_at column for soft deletes.
VARCHAR equivalent column.
VARCHAR equivalent with a length.
TEXT equivalent for the database.
TIME equivalent for the database.

############## #$table->uuid('id');######UUID equivalent for the database.###############4、表格建立完成後,直接執行,由於我之前很多表創建並沒有使用php artisan  migrate,所以直接運行該命令導致提示部分錶存在,所以,我把這個文件轉移到database下tmp目錄下,命令上添加--path 'database/tmp',再次運行成功###
php artisan  migrate
###5、資料庫中觀察即發現表已建立! ############相關推薦:###最新的五個Laravel影片教學#########

以上是五步驟搞定Laravel Migrations的使用的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:segmentfault。如有侵權,請聯絡admin@php.cn刪除
超越Zoom Call:連接分佈式團隊的創意策略超越Zoom Call:連接分佈式團隊的創意策略Apr 26, 2025 am 12:24 AM

ToenhanceGaimentAndCohesionAmongDistributedTeamSbeyondzoom,實施策略:1)組織virtualCoffeebreaksforinfornformalchats,2)useasynchronoustoolslikeslikeslikeslikeslikeslackfornon worksdiscusions,3)3)介紹cristiongamificitygamificationgamificationgamificationgamificationgamificationgamificationwithteamgamegamesorchallengesorchallenges,and4)

最新的Laravel版本中有什麼破壞變化?最新的Laravel版本中有什麼破壞變化?Apr 26, 2025 am 12:23 AM

Laravel10 IntroducesseveralbreakingChanges:1)Itrequiresphp8.1orhigher,2)TherOuteserviceProviderNowSabootMethodForloadingRoutes,3)thewithtimestamps()MethodOneLoquentRectrationShipsipsississisdeprected,and4))

生產力悖論:在遠程設置中保持重點和動力生產力悖論:在遠程設置中保持重點和動力Apr 26, 2025 am 12:17 AM

tomaintainfocusandmotivationInremotework,createStructuredEnvorment,託管式構成,促進性,促進性通過socialescialactionsions andgoalsetting,維持工作勞動生平,維持且蘇聯核酸鹽學。 1)setupadeDedworkspadedworkspacepaceandstickeandsticketicktickticktoorine aroutine。

從遠處建立信任:在分佈式環境中促進協作從遠處建立信任:在分佈式環境中促進協作Apr 26, 2025 am 12:13 AM

TofosterCollaboraboraboraboraboraboraboraboraborateMoteTeams,實施策略:1)建立規範的,結構性的通用性在PersonalCheck-Ins,2)Usecollaborativetoolsfortransparenty,3)識別sectizeandcelebrateachivements,和4)FosterActultructulcultultrustrustrustandAdadAptAptaptaptibality。

最新的Laravel版本的主要功能是什麼?最新的Laravel版本的主要功能是什麼?Apr 26, 2025 am 12:01 AM

Laravel的最新版本主要特色包括:1.LaravelOctane提升应用性能,2.改进的模型工厂支持关系和状态定义,3.增强的Artisan命令,4.改进的错误处理,5.新增的Eloquent访问器和修改器。这些功能显著提升了开发效率和应用性能,但需谨慎使用以避免潜在问题。

包容的幻想:解決偏遠工作中的孤立和孤獨感包容的幻想:解決偏遠工作中的孤立和孤獨感Apr 25, 2025 am 12:28 AM

Tocombatisolationandlonelinessinremotework,companiesshouldimplementregular,meaningfulinteractions,provideequalgrowthopportunities,andusetechnologyeffectively.1)Fostergenuineconnectionsthroughvirtualcoffeebreaksandpersonalsharing.2)Ensureremoteworkers

Laravel用於全堆棧開發:綜合指南Laravel用於全堆棧開發:綜合指南Apr 25, 2025 am 12:27 AM

laravelispularfullull-stackDevelopmentBecapeitOffersAsAseAseAseAseBlendOfbackendEdpoperandPowerandForterFlexibility.1)ITSbackEndCapaPabilities,sightifyDatabaseInteractions.2)thebladeTemplatingEngingEngineAllolowsLows

視頻會議攤牌:為遠程會議選擇正確的平台視頻會議攤牌:為遠程會議選擇正確的平台Apr 25, 2025 am 12:26 AM

選擇視頻會議平台的關鍵因素包括用戶界面、安全性和功能。 1)用戶界面應直觀,如Zoom。 2)安全性需重視,MicrosoftTeams提供端到端加密。 3)功能需匹配需求,GoogleMeet適合簡短會議,CiscoWebex提供高級協作工具。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

mPDF

mPDF

mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),