Joh*_*acy 3 migration laravel laravel-5 laravel-5.1
如何正确更改/更新我的迁移,我使用的是 Laravel 5.1。
文档说我应该使用更改来更新列,例如:
$table->string('color', 10)->change();
Run Code Online (Sandbox Code Playgroud)
但是我必须把它放在迁移中的什么地方,我必须使用什么命令来更新一个简单的 php artisan migrate?
到目前为止我试过这个:
public function up()
{
Schema::create('products', function (Blueprint $table)) {
$table->string('color', 5);
});
Schema::table('products', function (Blueprint $table)) {
$table->string('color', 10)->change();
});
}
Run Code Online (Sandbox Code Playgroud)
并使用了这个命令:
php artisan migrate
Run Code Online (Sandbox Code Playgroud)
但它没有改变。
首先,创建新迁移以更改现有表列。
php artisan make:migration update_products_table
Run Code Online (Sandbox Code Playgroud)
然后你应该up()
在你的新迁移中执行这个内部方法:
Schema::table('products', function (Blueprint $table) {
$table->string('color', 10)->change();
});
Run Code Online (Sandbox Code Playgroud)
因此,您将有两次迁移。首先确实已经创建products
了color
字符串长度错误的表。
第二次迁移会将color
字符串长度从 5更改为 10。
创建秒迁移后,php artisan migrate
再次运行,更改将应用于表。
归档时间: |
|
查看次数: |
14645 次 |
最近记录: |