【发布时间】:2016-12-19 13:29:20
【问题描述】:
我的迁移是这样的:
public function up()
{
Schema::create('tests', function (Blueprint $table) {
$table->increments('id_test');
$table->string('name', 50);
$table->timestamps();
$table->softDeletes();
});
}
public function down()
{
Schema::drop('tests');
}
我想更改数据类型并在表测试中添加列。然后更新数据库中的表。我这样编辑:
public function up()
{
Schema::create('tests', function (Blueprint $table) {
$table->increments('id');
$table->string('id_test', 18);
$table->string('name', 50);
$table->timestamps();
$table->softDeletes();
});
}
public function down()
{
Schema::drop('tests');
}
然后我运行:php artisan migrate:refresh
我在数据库中丢失了数据
有没有人可以帮助我?
【问题讨论】:
-
简单:创建一个 new 迁移。不要编辑旧的。在
up()方法中添加新列,并在down()方法中删除它。然后只需php artisan migrate运行更改。php artisan migrate:rollback扭转它。 -
您可以通过reading the very thorough documentation了解更多关于迁移的信息
标签: php mysql laravel laravel-5.3