1 回答

TA貢獻(xiàn)2041條經(jīng)驗 獲得超4個贊
配置數(shù)據(jù)庫
我們安裝wamp,并且使用mysql方式。用wamp自帶的phpMyAdmin添加一個名字為laravel的數(shù)據(jù)庫。
app/config目錄下,database.php包含數(shù)據(jù)庫的配置,打開并修改mysql部分為如下:
建立一個遷移
在cmd里面,定位到 laravel所在目錄,執(zhí)行如下命令:
php artisan migrate:make --create=articles
其中,--create=articles 就表示建立數(shù)據(jù)表
這樣,在 app/database/migrations/目錄下,會生成一個遷移文件。文件名是 時間編號+create_articles_table.php本例是:2015_01_25_144256_create_articles_table.php
修改遷移
打開文件,2015_01_25_144256_create_articles_table.php
里面類CreateAritclestable負(fù)責(zé)管理數(shù)據(jù)庫,它的up方法調(diào)用Schema::create來建立一個數(shù)據(jù)表articles,默認(rèn)已經(jīng)包括一個自增的id和時間字段。
如紅線所示,我們再添加兩個字段title 和 text。
執(zhí)行遷移
在cmd命令窗口,執(zhí)行如下命令:
php artisan migrate
然后查看數(shù)據(jù)庫laravel
- 1 回答
- 0 關(guān)注
- 601 瀏覽
添加回答
舉報