laravel - Doctrine/dbal - 尝试将字符串字段更改为日期时出错
问题描述
我使用 Laravel 迁移创建了一个表。我将两个字段作为字符串迁移,但我想要一个作为日期,一个作为整数。所以我创建了一个新的迁移来更改这些字段。我安装了学说/dbal。我使用 Laravel 6.5。但是,尝试迁移时出现错误。
移民
public function up()
{
Schema::table('follow_up_task', function (Blueprint $table) {
$table->date('next_follow_date')->change();
$table->integer('follow_stop_after')->change();
});
}
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]: 语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以utf8mb4_unicode_ci
在第 1 行的 'CHARACTER SET utf8mb4 DEFAULT NULL COLLATE , CHANGE recurrin' 附近使用正确的语法(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/laravel-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' at line 1") /home/vagrant/laravel-api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:63
2 PDOException::("SQLSTATE[42000]: 语法错误或访问冲突:1064 您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,以在 'CHARACTER SET utf8mb4 DEFAULT NULL 附近使用正确的语法COLLATE utf8mb4_unicode_ci
, CHANGE recurrin' at line 1") /home/vagrant/laravel-api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:61
请使用参数 -v 查看更多详细信息。
解决方案
我们也可以使用
$table->date('next_follow_date')->charset('')->collation('')->change();
为了避免这个问题
推荐阅读
- java - 为什么我们不能增加 asList() 返回的 ArrayList 对象的大小?
- java - 如何在 Java 中以特定方式对 JSON 列号进行排序
- node.js - 部署后如何解决heroku中的page not found错误
- python - 使用模式 coverage-reports/coverage.xml 未找到 sonar.python.coverage.reportPaths 的报告
- android - 两行约束布局
- python - 当我试图通过 BeautifulSoup 获取它时,它变成空的
我正在尝试从网站解析表格
https://www.kp.ru/best/kazan/abiturient_2018/ivmit/
。Chrome 的 DevTools 向我展示了该表:<div class="t431__table-wapper" data-auto-correct-mobile-width="false"> <tab
- python - .csv 加载重复每个单元格中一列中的所有条目
- python - 从python for循环函数返回一个值
- javascript - 与 Angular 等其他主要 JS 框架不同,为什么 ReactJS 需要这么多外部工具来构建应用程序?
- macos - 如何创建一个接受字符串并将其转换为另一个托管字符串的脚本?