mysql - 为什么 active_storage :install's migration (v5. 2.1) 运行时会生成无效的 MySQL 语法?

标签 mysql ruby-on-rails rails-migrations rails-activestorage ruby-on-rails-5.2

我已将 Rails 4.x 应用程序升级到 v5.2.1。升级顺利,应用程序运行良好。不过,我现在已经运行了 Rails active_storage:install,它创建了一个迁移来为 ActiveStorage 创建表。

迁移创建得很好,看起来还不错。但是,当运行 Rails db:migrate 时,我得到:

Mysql2::Error: 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 'string NOT NULL, `filename` string NOT NULL, `content_type` string, `metadata` t' at line 1: CREATE TABLE `active_storage_blobs` (`id` integer NOT NULL AUTO_INCREMENT PRIMARY KEY, `key` string NOT NULL, `filename` string NOT NULL, `content_type` string, `metadata` text, `byte_size` bigint NOT NULL, `checksum` string NOT NULL, `created_at` datetime NOT NULL, UNIQUE INDEX `index_active_storage_blobs_on_key`  (`key`)) ENGINE=InnoDB

很明显,它将 t.string 翻译为“CREATE TABLE (name string) <-- “string”,而不是 varchar 或其他东西。为什么会这样?

当我使用 varchars 而不是“string”手动运行此 CREATE TABLE 时,表创建得很好。

最佳答案

好吧,我解决了它:这是由猴子补丁覆盖 sql_type 引起的,Rails 4.x 中的 utf8mb4 需要它来修复主键类型。我已经删除了该初始化程序,并且迁移现在可以进行。感谢所有花时间思考这个问题的人。

关于mysql - 为什么 active_storage :install's migration (v5. 2.1) 运行时会生成无效的 MySQL 语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52436984/

相关文章:

mysql - 连接/合并两个表,即兴/组成 "missing"条目

ruby-on-rails - 来自 Ruby on Rails 的 Facebook 应用邀请

ruby-on-rails - 在 ruby​​ 代码中将参数作为 param={} 传递

mysql - 进行查询时使用等于还是不等于更好?

PHP 警告 mysqli_fetch_assoc()

php - 如何以编程方式在共享 Linux 托管计划上创建 MySQL 数据库

ruby-on-rails - : rails vs. bin/rails 有什么区别?

ruby-on-rails - 如何使用 rails migration 运行 rake 任务

ruby-on-rails - Rails 迁移添加一个 null : false column with an initial value that's not an ongoing default

ruby - Gem 中的测试需要测试迁移生成器并为测试应用迁移