Laravel 5 迁移更改现有列的长度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36469496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5 Migration change length of existed column
提问by Sang Tr?n
It not work, I search so many ways, How can I change length of value in laravel 5
它不起作用,我搜索了很多方法,如何更改 Laravel 5 中的值长度
public function up()
{
Schema::table('articles', function (Blueprint $table) {
$table->string('name',50)->change();
});
}
Thank you all for reading!
感谢大家阅读!
回答by Alexey Mezenin
Regarding documentation, your example should work:
关于文档,您的示例应该可以工作:
Schema::table('users', function ($table) {
$table->string('name', 50)->change();
});
Just run php artisan migrate
command to execute it.
只需运行php artisan migrate
命令来执行它。
回答by victorf
At least in Laravel 5.6, if it is requiring Doctrine DBAL and you don't want to install it now for any reason, you can try this:
至少在 Laravel 5.6 中,如果它需要 Doctrine DBAL 并且您出于任何原因不想现在安装它,您可以尝试以下操作:
<?php
// ...
Schema::table('users', function ($table) {
DB::statement('ALTER TABLE users MODIFY COLUMN name VARCHAR(50)');
});
回答by Chris
There is an outstanding (open for multiple years and still being discussed) issue related to Doctrine DBAL (discussion here: https://github.com/laravel/framework/issues/1186).
有一个与 Doctrine DBAL 相关的悬而未决的(开放多年并仍在讨论)问题(此处讨论:https: //github.com/laravel/framework/issues/1186)。
The deceptive part of this issue is that a ->change()
will fail if any column is of type enum (not just the column you are changing!)
这个问题的欺骗性部分是,->change()
如果任何列是 enum 类型(不仅仅是您正在更改的列!)
If your table has an enum column, you need to revert to using an alter statement (note you don't need to wrap it in a Table::schema
:
如果你的表有一个 enum 列,你需要恢复到使用 alter 语句(注意你不需要将它包装在 a 中Table::schema
:
DB::statement('ALTER TABLE users MODIFY COLUMN name VARCHAR(50)')
DB::statement('ALTER TABLE users MODIFY COLUMN name VARCHAR(50)')