doctrine / dbal-尝试将字符串字段更改为日期时出错
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了doctrine / dbal-尝试将字符串字段更改为日期时出错相关的知识,希望对你有一定的参考价值。
我使用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();
});
}
但是我有错误
IlluminateDatabaseQueryException : 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查看更多详细信息。
然后可能是由于doctrine/dbal
v2.10.0
软件包的最新版本中的错误。
您可以将doctrine/dbal
中的composer.json
程序包降级为v2.9.3
。
以上是关于doctrine / dbal-尝试将字符串字段更改为日期时出错的主要内容,如果未能解决你的问题,请参考以下文章
Doctrine DBAL 可以与 ORM Query Builder 混合使用吗?
Doctrine DBAL ->execute() 和 Hydration,DB2 字段名称包括“#”
使用 insert() 方法通过 PHP Doctrine\DBAL 2 插入 DateTime 值
在作曲家 laravel 上安装依赖项(doctrine/dbal)