PHP:laravel5.3:数据库的迁移

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_43731793/article/details/101602840

数据库的迁移

20:00
0、数据库迁移就像是数据库的版本控制 (不建议初学者使用)

1、创建数据库迁移
	php artisan make:migration create_table_news
	新的迁移文件将会被放置在 database/migrations 目录中。每个迁移文件的名称都包含了一个时间戳,以便让 Laravel 确认迁移的顺序。
	 public function up()
	{
	    Schema::create('news', function (Blueprint $table) {
	        $table->increments('id');
	        $table->string('title');
	        $table->string('text');
	    });
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
	    Schema::dropIfExists('news');
	}

2、使用迁移
	php artisan migrate

	调用迁移中的 up方法

3、返回
	php artisan migrate:rollback

	返回迁移中的 down方法

猜你喜欢

转载自blog.csdn.net/weixin_43731793/article/details/101602840
今日推荐