2017-08-09 185 views
1

嘗試在Laravel 5.2遷移數據列類型更改爲tinyInteger:更改列類型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. 

難道我做錯了什麼?

+0

是否包含在你的''composer.json'主義/ dbal'? – Jerodev

+0

@Jerodev yes,「doctrine/dbal」:composer.json中的「^ 2.5」 – mpet

回答

2

事實上主義DBAL不支持tinyint你可以從他們的文檔here

不幸的是讀爲好,laravel指出,tinyint不能改變。檢查here

我需要有人證明這是錯誤的,因爲我必須使用smallInteger因爲我的項目之一的這個問題。我想也許boolean()可能是解決方案。我還沒有嘗試過。

enter image description here

-1

試試這個 架構::表( '表名',函數(藍圖$表){$ 表 - > tinyInteger( 'COLUMN_NAME') - >默認值(0) - >更改();

0

我希望,這將解決您的問題

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