建立 migrate 檔案
$ php artisan make:migration create_options_table
新增內容
- 資料庫語法
CREATE TABLE `options` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` VARCHAR(200) NOT NULL COLLATE 'utf8mb4_unicode_ci',
`sort` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
`status` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1',
`created_at` TIMESTAMP NULL DEFAULT NULL,
`updated_at` TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `status` (`status`)
)
- migrate 寫法
database\migrations\2017_07_13_164117_create_options_table.php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateOptionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// 各類選單選項
Schema::create('options', function (Blueprint $table) {
$table->increments('id');
$table->string('title')->length(200);
$table->tinyInteger('sort')->length(1)->unsigned()->default(0);
$table->tinyInteger('status')->length(1)->unsigned()->default(1);
$table->timestamps();
$table->index('status', 'status');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('options');
}
}
執行 migrate
$ php artisan migrate