Php 将列类型更改为tinyInteger
尝试在Laravel 5.2迁移中将数据列类型更改为tinyInteger:Php 将列类型更改为tinyInteger,php,laravel,migration,laravel-5.2,Php,Laravel,Migration,Laravel 5.2,尝试在Laravel 5.2迁移中将数据列类型更改为tinyInteger: <?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class AlterTableNameTableChangeNotificationSentTinyint extends Migration { /** * Run the migrations.
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AlterTableNameTableChangeNotificationSentTinyint extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('table_name', function ($table) {
$table->tinyInteger('column_name')->default(0)->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
我做错什么了吗?试试这个
Schema::table('table_name',函数(Blueprint$table){
$table->tinyInteger('column_name')->default(0)->change();我希望这能解决您的问题
DB::statement("ALTER TABLE table_name CHANGE COLUMN column_name column_name TINYINT UNSIGNED NOT NULL");
实际上,Dbal不支持
tinyint
您可以从他们的文档中读取
同样不幸的是,laravel声明不能更改tinyint
。请检查
我需要有人证明这是错误的,因为我的一个项目因为这个问题而不得不使用smallInteger。我想,boolean()
可能是解决方案。不过我还没有尝试过
这样做
将tinyInteger更改为smallInteger
我也遇到了同样的问题,并发现了这个问题。它对我很有效。但它让我产生了一个问题,为什么creator不更新到
原则/dbal
包。也许这个解决方案在某些情况下会导致错误?希望有人在这个答案中解释。你能使用布尔值吗
或
您是否在您的composer.json
中包含条令/dbal
?@Jerodev yes,“条令/dbal”:“^2.5”在composer.json中
DB::statement("ALTER TABLE table_name CHANGE COLUMN column_name column_name TINYINT UNSIGNED NOT NULL");
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\SmallIntType;
if (!Type::hasType('integer')) {
Type::addType('integer', SmallIntType::class);
}
$table->smallInteger('column_name')->tinyInteger('column_name')->unsigned()->change();