Php Laravel 5.4迁移枚举在MySQL中失败
当我尝试应用迁移时,出现以下错误:Php Laravel 5.4迁移枚举在MySQL中失败,php,mysql,laravel-5,laravel-migrations,Php,Mysql,Laravel 5,Laravel Migrations,当我尝试应用迁移时,出现以下错误: [Doctrine\DBAL\DBALException] Unknown database type enum requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it. 应用了迁移,在数据库上创建了enum列,我得到了错误,因此无法执行nexts迁移,因为此迁移会引发此错误 在服务器中,我使用了MySQL版本5.7.17 这是我的迁移代码: class AddDocumen
[Doctrine\DBAL\DBALException]
Unknown database type enum requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it.
应用了迁移,在数据库上创建了enum列,我得到了错误,因此无法执行nexts迁移,因为此迁移会引发此错误
在服务器中,我使用了MySQL版本5.7.17
这是我的迁移代码:
class AddDocumentUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('document', 9)->unique();
$table->enum('document_type', ['dni', 'nie', 'nif', 'cif']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('document');
$table->dropColumn('document_type');
});
}
}
谢谢;) 可以找到与laravel严格相关的信息。我强烈建议你读这篇文章。这不是拉威尔的问题,这是一个错误的学说,因为永远 从上面的问题线程中,用户
henritoivar
有一个有趣的想法
在此引述:
这对我在laravel 5.2中使用doctrine/dbal@^2.5时起到了作用。当你
在表上有一个枚举,您想更改任何列
在桌子上,您必须:
我不知道这对你是否有效,但值得一试
我本想把这篇文章作为评论发表的,但这篇文章读得太长了 : 条令2的类型系统由飞锤组成,即 任何给定类型只有一个实例。其他类型也有 不包含状态。这两种假设都使工作变得相当复杂 使用开发人员经常使用的枚举类型MySQL。 当将枚举与未调整的Doctrine 2应用程序一起使用时,由于未知原因,您将从模式工具命令中获得错误 数据库类型“enum”。默认情况下,条令不映射MySQL枚举 类型转换为条令类型。这是因为枚举包含状态(它们的 允许的值)和条令类型不允许 从技术上讲,这是可以解决的。看见但这与拉威尔所基于的symfony密切相关
: 当前不支持重命名表中也包含enum类型列的任何列>
虽然这不是一个答案,但我希望它能为你指明正确的方向,或者至少让你知道你所面临的是什么
更多相关问题:
在包含枚举类型的迁移文件中,添加具有以下内容的构造函数方法:
public function\uuuu construct(){
//寄存器枚举类型
DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum','string');
}
这在Laravel 5.2中对我有效。您可以尝试在更高的级别添加此内容,但这对我来说更快:)阅读laravel文档,我发现:“以下列类型无法”更改“:char,double,enum,mediumInteger,timestamp,tinyInteger,ipAddress,json,jsonb,macAddress,mediumIncrements,morphs,nullableMorphs,nullablemstamps,softDeletes,timeTz,timestamps,timestamps,timestastz,unsignedMediumInteger,unsignedTinyInteger,uuid。”但我并没有尝试改变列,我正在尝试创建它。
public function up()
{
Schema::getConnection()->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
Schema::table('jobs', function(Blueprint $table)
{
$table->decimal('latitude', 10, 6)->nullable()->change();
});
}