ActiveRecord Migrations in Rails 2.1 create incorrect create table SQL for DB2
------------------------------------------------------------------------------
Key: JRUBY-2702
URL: http://jira.codehaus.org/browse/JRUBY-2702
Project: JRuby
Issue Type: Bug
Components: ActiveRecord-JDBC
Affects Versions: JRuby 1.1.2
Environment: activerecord-jdbc-adapter-0.8.2, Rails 2.1, DB2 9
Reporter: Josh Price
Using a simple create table migration using JRuby 1.1.2 and
activerecord-jdbc-adapter 0.8.2 on a DB2 9.0 database:
{noformat}
create_table :mytable do |t|
t.string :string_field
end
{noformat}
When migrated the following error was produced:
ActiveRecord::ActiveRecordError: DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601,
SQLERRMC: ,;5) DEFAULT NULL NULL;<references_spec>: CREATE TABLE mytable (id
int generated by default as identity (start with 42) primary key, string_field
varchar(255) DEFAULT NULL NULL)
The error is caused by the fact that DB2 doesn't accept a directive to make a
field to be explicitly nullable.
The following change to ActiveRecord between Rails 2.0.2 and 2.1 seems to have
caused the problem:
http://github.com/rails/rails/commit/10ef65a3b054270ed3d458ec8eb7c2b9a3e638f7
This can be fixed by adding the following method to
*lib/jdbc_adapter/jdbc_db2.rb* reverts the activerecord functionality back to
that of Rails 2.0.2 for the DB2 adapter.
{noformat}
def add_column_options!(sql, options) #:nodoc:
sql << " DEFAULT #{quote(options[:default], options[:column])}" if
options_include_default?(options)
sql << " NOT NULL" if options[:null] == false
end
{noformat}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email