您好,登錄后才能下訂單哦!
這篇文章主要介紹laravel使用命令行結(jié)合代碼創(chuàng)建數(shù)據(jù)表的方法,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
雖然可以直接在數(shù)據(jù)庫(kù)中創(chuàng)建數(shù)據(jù)表,但是不便于以后項(xiàng)目的遷移。現(xiàn)使用命令行結(jié)合代碼的方式來(lái)進(jìn)行生成。
php artisan make:migration create_table_customers
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateTableCustomers extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('customers', function (Blueprint $table) { $table->increments('id'); $table->string('mobile')->nullable()->unique(); $table->string('email')->unique(); $table->string('website')->default('website')->comment('站點(diǎn):applet、website'); $table->string('store_id')->default('1')->comment('店鋪 ID'); $table->string('first_name'); $table->string('last_name'); $table->integer('appellation')->comment('稱謂'); $table->dateTime('birthday')->comment('生日'); $table->string('province')->comment('省'); $table->string('city')->comment('市'); $table->string('district')->comment('區(qū)/縣'); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('customers'); } }
php artisan migrate
以上是“l(fā)aravel使用命令行結(jié)合代碼創(chuàng)建數(shù)據(jù)表的方法”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。