doctrine / dbal-尝试将字符串字段更改为日期时出错

问题描述 投票:0回答:1

我使用laraval迁移创建表。我将两个字段迁移为字符串。但我想要一个作为日期,一个作为整数。因此,我创建了一个用于更改这些字段的新迁移。我安装了教义/ dbal。我使用laravel 6.5。但是尝试迁移时出现错误。我的迁移是

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::table('follow_up_task', function (Blueprint $table) {
        $table->date('next_follow_date')->change();
        $table->integer('follow_stop_after')->change();
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('follow_up_task', function (Blueprint $table) {
        $table->string('next_follow_date')->change();
        $table->string('follow_stop_after')->change();
    });
}

但是我有错误

  Illuminate\Database\QueryException  : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE recurrin' at line 1 (SQL: ALTER TABLE recurring_tasks CHANGE next_recurring_date next_recurring_date DATE CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE recurring_stop_after recurring_stop_after INT CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`)

at /home/vagrant/flowtopia-api/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
665|         // If an exception occurs when attempting to run a query, we'll format the error
666|         // message to include the bindings with SQL, which will make this exception a
667|         // lot more helpful to the developer instead of just the database's errors.
668|         catch (Exception $e) {
669|             throw new QueryException(
670|                 $query, $this->prepareBindings($bindings), $e
671|             );
672|         }
673| 

Exception trace:

1 Doctrine \ DBAL \ Driver \ PDOException::(“ SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法有错误;请查看与您的MySQL服务器版本相对应的手册,以获取正确的语法。在“ CHARACTER SET utf8mb4 DEFAULT NULL COLLATE utf8mb4_unicode_ci,CHANGE recurrin”第1行附近使用”)/home/vagrant/flowtopia-api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:63

2 PDOException::(“ SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法有错误;请查看与MySQL服务器版本相对应的手册,以获取在'CHARACTER SET utf8mb4附近使用的正确语法。默认为NULL COLLATE utf8mb4_unicode_ci,更改在第1行重复发生”)/home/vagrant/flowtopia-api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:61

请使用参数-v查看更多详细信息。

laravel doctrine dbal
1个回答
0
投票

然后可能是由于doctrine/dbal v2.10.0软件包的最新版本中的错误。

您可以将doctrine/dbal中的composer.json程序包降级为v2.9.3

© www.soinside.com 2019 - 2024. All rights reserved.