laravel 将列类型更改为 tinyInteger
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45591455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change column type to tinyInteger
提问by mpet
Trying to change data column type to tinyInteger in a Laravel 5.2 migration:
尝试在 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()
{
//
}
}
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?
难道我做错了什么?
回答by Oluwatobi Samuel Omisakin
Indeed Doctrine Dbal does not support tinyint
you can read from their doc here
事实上,Doctrine Dbal 不支持tinyint
你可以在这里阅读他们的文档
Unfortunately as well, laravel stated that tinyint
cannot be changed. Check here
不幸的是,laravel 声明tinyint
不能更改。在这里查看
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.
我需要有人证明这是错误的,因为我不得不使用 smallInteger 因为我的一个项目的这个问题。我想也许boolean()
可能是解决方案。不过我还没有尝试过。
回答by Kumar Subedi
Do This
做这个
Change tinyInteger to smallInteger
将 tinyInteger 更改为 smallInteger
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\SmallIntType;
if (!Type::hasType('integer')) {
Type::addType('integer', SmallIntType::class);
}
回答by durduliu2009
i hope that this will solve your issue
我希望这能解决你的问题
DB::statement("ALTER TABLE table_name CHANGE COLUMN column_name column_name TINYINT UNSIGNED NOT NULL");
回答by Nikita
try this Schema::table('table_name', function (Blueprint $table) { $table->tinyInteger('column_name')->default(0)->change();
试试这个 Schema::table('table_name', function (Blueprint $table) { $table->tinyInteger('column_name')->default(0)->change();