欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Change column type to tinyInteger Unknown column type "tinyinteger" requested. \Doctrine\DBAL


Trying to change data column type to tinyInteger in a Laravel 5.2 migration:

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

I'm getting an error:

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. 

Am I doing something wrong?

shareimprove this question
 
   
Did you include doctrine/dbal in your composer.json? – Jerodev Aug 9 at 13:08
   
@Jerodev yes, "doctrine/dbal": "^2.5" in composer.json – mpet Aug 10 at 17:57

3 Answers 正确答案

Indeed Doctrine Dbal does not support tinyint you can read from their doc here

Unfortunately as well, laravel stated that tinyint cannot be changed. Check here

I need someone to prove this as wrong, because I had to use smallInteger because of this issue for one of my projects. I am thinking maybe boolean() might be the solution. I have not tried this though.

enter image description here

shareimprove this answer
 

try this Schema::table('table_name', function (Blueprint $table) { $table->tinyInteger('column_name')->default(0)->change();

shareimprove this answer
 

i hope that this will solve your issue

DB::statement("ALTER TABLE themes MODIFY  theme_is_wap TINYINT DEFAULT 0");
DB::statement("ALTER TABLE table_name CHANGE COLUMN column_name column_name TINYINT UNSIGNED NOT NULL");
shareimprove this answer
 

来自 https://stackoverflow.com/questions/45591455/change-column-type-to-tinyinteger

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

在数据列类型更改为tinyinteger在laravel 5.2迁移:

<?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. 

我做错了什么?

分享改善这个问题
 
  
你有没有doctrine/dbal在你的composer.jsonjerodev8月9日下午1点08分
  
“Jerodev是的,”说:“^ /动态平衡“2.5”composer.jsonMPET8月10日17:57

3个答案 正确答案

的确,Dbal不支持原则tinyint你可以从他们的医生看在这里

不幸的是,嗯,laravel说tinyint不能改变的。检查在这里

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

enter image description here

分享提高这个答案
 

try thisSchema::table('table_name', function (Blueprint $table) { $table->tinyInteger('column_name')->default(0)->change();

分享提高这个答案
 

我希望这能解决你的问题

DB::statement("ALTER TABLE themes MODIFY  theme_is_wap TINYINT DEFAULT 0");
DB::statement("ALTER TABLE table_name CHANGE COLUMN column_name column_name TINYINT UNSIGNED NOT NULL");
分享提高这个答案
 

来自 https://stackoverflow.com/questions/45591455/change-column-type-to-tinyinteger

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

普通分类: