【问题标题】:Problem when adding a MySQL enum column via ruby Rails migration通过 ruby​​ Rails 迁移添加 MySQL 枚举列时出现问题
【发布时间】:2019-05-08 14:03:35
【问题描述】:

我正在尝试通过以下方式添加 MySQL 枚举列:

# frozen_string_literal: true
class AddStatusToTasks < ActiveRecord::Migration[6.0]
  def up
    execute <<-SQL
        ALTER TABLE tasks ADD status enum('to_do', 'doing', 'done');
    SQL
  end
  def down
    remove_column :tasks, :status
  end
end

但我得到了错误:

AddStatusToTasks: migrating =================================
-- execute("        ALTER TABLE tasks ADD status enum('to_do', 'doing', 'done');\n")
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: near "'to_do'": syntax error

我的模特喜欢的样子:

class Task < ApplicationRecord
  belongs_to :user
  enum status: { to_do: 'to_do', doing: 'doing', done: 'done' }
end

我其实是按照here的指南来的,但是我找不到问题。

提前感谢大家的帮助!

【问题讨论】:

    标签: mysql ruby-on-rails ruby enums rails-migrations


    【解决方案1】:

    SQLite3::SQLException -- 您正在 SQLite 数据库上执行此查询,而不是 MySQL。您使用的环境是否正确?

    【讨论】:

      猜你喜欢
      • 2019-12-08
      • 2019-08-16
      • 1970-01-01
      • 1970-01-01
      • 2013-05-03
      • 2016-08-14
      • 1970-01-01
      • 2013-01-10
      • 1970-01-01
      相关资源
      最近更新 更多