简体   繁体   English

如何使用 Laravel 迁移将字符串列类型转换为 integer?

[英]How to convert string column type to integer using Laravel migration?

I am trying to alter the column datatype using Laravel migration.我正在尝试使用 Laravel 迁移来更改列数据类型。 But I am facing following error.但我面临以下错误。 Please help me out.请帮帮我。

Schema::table('files', function(Blueprint $table) {
    $table->integer('app_id')->change();
    $table->index(['app_id', 'filename']);
});

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CHARACTER SET utf8 DEFAULT 0 NOT NULL COLLATE utf8_unicode_ci ' at line 1 (SQL: ALTER TABLE files CHANGE app_id app_id INT CHARACTER SET utf8 DEFAULT 0 NOT NULL COLLATE utf8_unicode_ci ) check the manual that corresponds to your MySQL server version for the right syntax to use near 'CHARACTER SET utf8 DEFAULT 0 NOT NULL COLLATE utf8_unicode_ci ' at line 1 (SQL: ALTER TABLE files CHANGE app_id app_id INT CHARACTER SET utf8 DEFAULT 0 NOT NULL COLLATE utf8_unicode_ci )

As a alternative solution to https://github.com/doctrine/dbal/issues/3714 that is downgrading the doctrine/dbal package u can do:作为https://github.com/doctrine/dbal/issues/3714的替代解决方案,它正在降级学说/dbal package 你可以这样做:

Schema::table('member_section', function (Blueprint $table) {
    $table->bigInteger('type')->charset(null)->collation(null)->change();
});

Your issue is most likely caused by a bug in the most recent version of the doctrine/dbal package.您的问题很可能是由最新版本的doctrine/dbal package 中的错误引起的。 The issue was introduced with v2.10.0 .该问题是在v2.10.0中引入的。

You can always downgrade the package in your composer.json to v2.9.3 it should work just fine.您可以随时将composer.json中的 package 降级到v2.9.3 ,它应该可以正常工作。

See the offical issue here: https://github.com/doctrine/dbal/issues/3714在此处查看官方问题: https://github.com/doctrine/dbal/issues/3714

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM