迁移:创建数据表和删除数据表的操作;
-
迁移文件的位置:database/migrations
-
创建迁移文件:php artisan make:migration 迁移文件名
php artisan make:migration create_paper_table //创建表
-
编写迁移文件:
-
// 创建表
public function up()
{
Schema::create(‘paper’, function (Blueprint $table) {
// $table->列类型方法(字段名,[长度/值范围])->列修饰方法();
$table->bigIncrements(‘id’);
$table->timestamps();
});
}
// 删除表
public function down()
{
Schema::dropIfExists(‘paper’);
}
运行迁移: -
当前项目第一次执行迁移文件:php artisan migrate:install 生成一个迁移表(高版本可以省略)
-
需要执行up()方法:php artisan migrate
-
需要执行down()方法:php artisan migrate:rollback;删除的是同批次;最新批次的表;