我正在尝试使用Laravel5.6更改列数据类型。
我有一个表,其中两列的数据类型为text,但我想将其更改为longtext。我试过以下几点:
执行composer require doctrine/dbal
composer dump-autoload的
然后,...and为log_requests表创建了迁移2019_12_23_065820_change_response_column_data_type_in_log_requests_table.php。
...and然后是下面的脚本
public function up()
{
Schema::table('log_requests', function (Blueprint $table) {
$table->longText('request')->nullable()->change();
$table->longText('response')->nullable()->change();
});
}但是它并没有改变列的数据类型。有人能指引我吗?我哪里错了这样我就能修好它了?谢谢。
编辑的
在注释中请求迁移之后,我添加了迁移脚本:
public function up()
{
Schema::create('log_requests', function (Blueprint $table) {
$table->increments('id');
$table->bigInteger('user_id')->nullable()->unsigned();
$table->string('api_name')->nullable();
$table->string('url')->nullable();
$table->string('method')->nullable();
$table->string('ip_address')->nullable();
$table->string('status_code')->nullable();
$table->string('duration')->nullable();
$table->text('request')->nullable();
$table->text('response')->nullable();
$table->timestamps();
});
}发布于 2019-12-23 08:16:19
只需更改列注释,例如:
$table->mediumText('myColumn')->comment(' ')->change(); // up
$table->text('myColumn')->comment('')->change(); // down发布于 2019-12-25 14:06:55
这是一个关于doctorine如何对待文本的问题,它不区分长、中或普通文本,但是它可以通过更改size属性来完成。
$table->string('request', 4294967295)->change();
如per @andfelzapata在“https://github.com/laravel/framework/issues/9636”杂志中所述
发布于 2019-12-23 08:23:14
如果选择直接查询,则可以避免使用Dbal。
public function up()
{
\DB::statement('alter table log_requests modify request longtext null;');
\DB::statement('alter table log_requests modify response longtext null;');
}
public function down()
{
\DB::statement('alter table log_requests modify request text null;');
\DB::statement('alter table log_requests modify response text null;');
}https://stackoverflow.com/questions/59451801
复制相似问题