[英]Postgres and Laravel how to change column from type string to integer?
[英]How to convert string column type to integer using Laravel migration?
我正在尝试使用 Laravel 迁移来更改列数据类型。 但我面临以下错误。 请帮帮我。
Schema::table('files', function(Blueprint $table) {
$table->integer('app_id')->change();
$table->index(['app_id', 'filename']);
});
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 COLLATEutf8_unicode_ci
)
作为https://github.com/doctrine/dbal/issues/3714的替代解决方案,它正在降级学说/dbal package 你可以这样做:
Schema::table('member_section', function (Blueprint $table) {
$table->bigInteger('type')->charset(null)->collation(null)->change();
});
您的问题很可能是由最新版本的doctrine/dbal
package 中的错误引起的。 该问题是在v2.10.0
中引入的。
您可以随时将composer.json
中的 package 降级到v2.9.3
,它应该可以正常工作。
在此处查看官方问题: https://github.com/doctrine/dbal/issues/3714
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.