php – Laravel 5.4迁移ENUM在MySQL中失败

weixin_38065217 2019-09-12 11:31:24
当我尝试应用我的迁移时,我收到此错误: [Doctrine\DBAL\DBALException] Unknown database type enum requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it. 应用迁移,在数据库上创建枚举列,我得到错误,因此我无法执行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'); }); } } 谢谢 😉
...全文
32 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38068785 2019-09-12
  • 打赏
  • 举报
回复
与laravel严格相关的信息可以在here找到.我强烈建议你阅读线程.这不是一个laravel问题,它一直是Doctrine中的一个错误. 从上面的问题线程,用户henritoivar有一个有趣的想法. 引用这里: This worked for me in laravel 5.2 with doctrine/dbal@^2.5 . When you have an enum on your table and you want to change any of the columns on the table you will have to: public function up() { Schema::getConnection()->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); Schema::table('jobs', function(Blueprint $table) { $table->decimal('latitude', 10, 6)->nullable()->change(); }); } 我不知道这是否适合你,但值得一试. 我会发布这个评论,但这是一个该死的长读. From the official Doctrine documents: The type system of Doctrine 2 consists of flyweights, which means there is only one instance of any given type. Additionally types do not contain state. Both assumptions make it rather complicated to work with the Enum Type of MySQL that is used quite a lot by developers. When using Enums with a non-tweaked Doctrine 2 application you will get errors from the Schema-Tool commands due to the unknown database type “enum”. By default Doctrine does not map the MySQL enum type to a Doctrine type. This is because Enums contain state (their allowed values) and Doctrine types don’t. 从技术上讲,这可以解决.见here.但这与Laravel所依据的symfony严格相关. Laravel’s docs also stated that it has a problem with enums: Renaming any column in a table that also has a column of type enum is >not currently supported. 虽然这不是一个答案,但我希望它指出你正确的方向或至少让你知道你面临的是什么. 更多相关问题: How to enable ENUMs in Symfony 2 / Doctrine Laravel 5.1 Unknown database type enum requested

433

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧