要为现有模型创建表,您只需运行以下命令,
php artisan make:migration table_name
Run Code Online (Sandbox Code Playgroud)
并且,去 database -> migration -> date_with-table_name
在里面up(),输入你想要添加的表名和字段,如下所示;
Schema::create('table_name', function (Blueprint $table) {
$table->increments('id');
$table->string('field_2');
$table->string('field_3');
$table->string('field_4');
$table->date('field_5');
$table->string('field_6');
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
对于模型,只需创建一个模型即可,没有什么特别的,只需确保设置$tableif not 以下约定即可。
为了从现有数据库模式生成迁移,有一个包:
| 归档时间: |
|
| 查看次数: |
8124 次 |
| 最近记录: |