--table和--create选项可用来指定数据表的名称,或是该迁移被执行时是否将创建的新数据表。这些选项需在预生成迁移文件时填入指定的数据表: php artisan make:migration create_users_table--create=users php artisan make:migration add_votes_to_users_table--table=
2)修改已创建的数据表字段(make:migration add) 想要修改已创建的数据表,不能直接改原来的 migrate 文件,要新建一个迁移文件,命令如下: php artisan make:migration add_description_to_articles_table --table=articles php artisan make:migration change_description_on_articles_table --table=articles PS:其实migr...
$table->dropColumn(['votes', 'avatar', 'location']);//删除votes,avatar,location字段
--table 和--create 选项可用来指定数据表的名称,或是该迁移被执行时会创建的新数据表。这些选项需在预生成迁移文件时填入指定的数据表:php artisan make:migration add_votes_to_users_table --table=users php artisan make:migration create_users_table --create=users...
--table和--create选项可用来指定数据表的名称,或是该迁移被执行时会创建的新数据表。这些选项需在预生成迁移文件时填入指定的数据表: php artisan make:migration create_users_table--create=users php artisan make:migration add_votes_to_users_table--table=users ...
php artisan make:migration add_soft_delete_to_events --table=events 执行成功,输出内容如下:Created Migration: 2020_10_08_184402_add_soft_delete_to_events 接着在生成的迁移文件内实现迁移使用的 up 方法:public function up(){ Schema::table('events', function(Blueprint $table){ $table->...
php artisan make:migration add_votes_to_users_table –table=users 如果你想要指定生成迁移的自定义输出路径,在执行make:migration命令时可以使用–path选项,提供的路径应该是相对于应用根目录的。 3、迁移结构 迁移类包含了两个方法:up和down。up方法用于新增表,列或者索引到数据库,而down方法就是up方法的反操作...
php artisan make:migration add_votes_to_users_table --table=users php artisan make:migration create_users_table --create=users 第一个仅仅指定了迁移文件名称,一般我们给它起一个直观的名字,方便给自己和维护者提个醒 :-)第二个使用了 --table选项指定该迁移文件是对哪个表起作用的。第三个使用了 --...
php artisan make:migration add_state_id_to_events_table --table=events 手动实现迁移文件的修改:public function up(){ Schema::table('events', function (Blueprint $table) { $table->integer('state_id')->unsigned()->nullable();$table->foreign('state_id')->references('id')->on('states'...
1phpartisanmake:migrationcreate_users_table--create=users 2 3phpartisanmake:migrationadd_votes_to_users_table--table=users If you would like to specify a custom output path for the generated migration, you may use the--pathoption when executing themake:migrationcommand. The given path should be...