将列类型更改为 tinyInteger

2022-08-30 21:05:13

尝试在 Laravel 5.2 迁移中将数据列类型更改为 tinyInteger:

<?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()
    {
        //
    }
}

我收到一个错误:

Doctrine\DBAL\DBALException]                                                                                                                                                              
  Unknown column type "tinyinteger" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType().         You can get a list of all the known types wit  
  h \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database introspection then you might have forgot to register all database types for a Doctrine Type. Use Abstrac  
  tPlatform#registerDoctrineTypeMapping() or have your custom types     implement Type#getMappedDatabaseTypes(). If the type name is empty you might have a problem with the cache or forgot so  
  me mapping information. 

我做错了什么吗?


答案 1

事实上,Doctrine Dbal不支持你可以从他们的文档这里阅读tinyint

不幸的是,laravel也表示无法改变。查看此处tinyint

我需要有人来证明这是错误的,因为我不得不使用smallInteger,因为我的一个项目有这个问题。我想也许可能是解决方案。我还没有尝试过这个。boolean()

enter image description here


答案 2

我希望这将解决您的问题

DB::statement("ALTER TABLE table_name CHANGE COLUMN column_name column_name TINYINT UNSIGNED NOT NULL");

推荐