使用laravel 的artisan快速创建表
字段类型参考链接: 结构生成器
版本: Laravel 4.2
1. 创建migrate 文件
php artisan migrate:make create_lang_table
2. 编辑migrate文件
<?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateLangTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { // Schema::create('lang', function(Blueprint $table) { $table->increments('id');//主键自增 $table->string('local',50); //语言 $table->string('title',30); //标题 $table->tinyInteger('main')->nullable(); //主要语言 $table->tinyInteger('published')->default(1); //发布 $table->integer('ordering')->default(0); //排序 $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { // } }
3. 创建表
1 php artisan migrate
就会看到类似的信息:
1 vagrant@precise32:/var/www/html$ php artisan migrate 2 ************************************** 3 * Application In Production! * 4 ************************************** 5 6 Do you really wish to run this command? yes 7 Migrated: 2015_11_01_114540_create_lang_table