【问题标题】:MySQL issue with JRubyJRuby 的 MySQL 问题
【发布时间】:2016-02-14 16:22:12
【问题描述】:

当我尝试运行迁移时,出现以下错误:

 ActiveRecord::JDBCError:
 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: All parts
 of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use
 UNIQUE instead: CREATE TABLE `posts` (`id` int(11) DEFAULT NULL
 auto_increment PRIMARY KEY, `content` text, `created_at` datetime NOT
 NULL, `updated_at` datetime NOT NULL)
 ENGINE=InnoDBarjdbc/jdbc/RubyJdbcConnection.java:587:in `execute'

我的迁移文件是:

class CreatePosts < ActiveRecord::Migration
  def change
    create_table :posts do |t|
      t.text :content
      t.timestamps null: false
    end
  end
end

我的 database.yml 是:

default: &default
  adapter: mysql2
  username: user
  password: user

development:
  <<: *default
  database: blog_development

test:
  <<: *default
  database: blog_test

production:
  <<: *default
  database: blog_production

我的 Gemfile 中有 gem 'activerecord-jdbcmysql-adapter'

当我尝试使用 MRI 和 mysql2 gem 运行相同的迁移时,一切正常。

我应该怎么做才能解决它?

【问题讨论】:

  • 什么版本的导轨?
  • rails 的版本是 4.2.5
  • 奇怪,有一个类似的问题for earlier versions of rails。听起来这可能是activerecord-jdbcmysql-adapter 中的一个错误 - 我会尝试在 github 上创建一个问题。您可以通过在创建表时使用id: false 选项来解决问题,然后在第二次迁移中使用SQL 手动创建id 列。但这对于应该可以正常工作的东西来说是一个相当极端的黑客攻击。

标签: mysql ruby-on-rails ruby activerecord jruby


【解决方案1】:

activerecord-jdbcmysql-adapter 一直在 Rails 后面……这已经在 1-3-stable 分支上修复了,以后应该会随着 gem 发布 1.3.20

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-15
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多