Although it’s old, mig_constraints has sat in my rails plugin directory for a while now because it adds much needed foreign key support to ActiveRecord.
I’m on of those crazy guys that thinks a relational database should maintain relational integrity, so it’s been a staple of my rails projects for some time. Unfortunately when I recently upgraded to rails 2.3.4, it created a bizarre obscure error that seems to indicate it’s not compatible with rails 2.3 at all.
As far as I can tell, the best candidate for a replacement is this github project but I’ve not yet had the time to try it. For now I simply removed the plugin from my project and db:migrate reverted to a nice working state.
For maximum google-a-bility, the stacktrace I got when trying to run db:migrate with the incompatible plugin is included below:
/usr/bin/ruby -e STDOUT.sync=true;STDERR.sync=true;load($0=ARGV.shift) /usr/bin/rake db:migrate
(in /Users/leem/Software/bsheet)
== Â AddSuggestions: migrating =================================================
-- create_table(:suggestions)
rake aborted!
An error has occurred, all later migrations canceled:
Mysql::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 '' at line 1: CREATE TABLE suggestions (#<struct ActiveRecord::ConnectionAdapters::ColumnDefinition base=#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0x23d7eb0 @last_verification=0, @logger=#<Logger:0x1159a04 @level=0, @default_formatter=#<Logger::Formatter:0x11599c8 @datetime_format=nil>, @progname=nil, @logdev=#<Logger::LogDevice:0x11599a0 @filename="/Users/leem/Software/bsheet/log/webapp-development.log", @mutex=#<Logger::LogDevice::LogDeviceMutex:0x1159978 @mon_owner=nil, @mon_waiting_queue=[], @mon_entering_queue=[], @mon_count=0>, @dev=#<File:/Users/leem/Software/bsheet/log/webapp-development.log>, @shift_size=1048576, @shift_age=0>, @formatter=#<Logger::SimpleFormatter:0x263e744 @datetime_format=nil>>, @quoted_table_names={}, @runtime=428.263902664185, @quoted_column_names={:user_id=>"`user_id`", "suggestions_user_id_fkey"=>"`suggestions_user_id_fkey`", "id"=>"`id`"}, @config={:adapter=>"mysql", :username=>"root", :socket=>"/tmp/mysql.sock", :host=>"localhost", :password=>"*******", :database=>"broadersheet_testing1"}, @query_cache_enabled=false, @connection=#<Mysql:0x23dc154>, @connection_options=["localhost", "root", "root", "broadersheet_testing1", nil, "/tmp/mysql.sock"]>, name="id", type=:primary_key, limit=nil, precision=nil, scale=nil, default=nil, null=nil>, #<struct ActiveRecord::ConnectionAdapters::ColumnDefinition base=#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0x23d7eb0 @last_verification=0, @logger=#<Logger:0x1159a04 @level=0, @default_formatter=#<Logger::Formatter:0x11599c8 @datetime_format=nil>, @progname=nil, @logdev=#<Logger::LogDevice:0x11599a0 @filename="/Users/leem/Software/bsheet/log/webapp-development.log", @mutex=#<Logger::LogDevice::LogDeviceMutex:0x1159978 @mon_owner=nil, @mon_waiting_queue=[], @mon_entering_queue=[], @mon_count=0>, @dev=#<File:/Users/leem/Software/bsheet/log/webapp-development.log>, @shift_size=1048576, @shift_age=0>, @formatter=#<Logger::SimpleFormatter:0x263e744 @datetime_format=nil>>, @quoted_table_names={}, @runtime=428.263902664185, @quoted_column_names={:user_id=>"`user_id`", "suggestions_user_id_fkey"=>"`suggestions_user_id_fkey`", "id"=>"`id`"}, @config={:adapter=>"mysql", :username=>"root", :socket=>"/tmp/mysql.sock", :host=>"localhost", :password=>"*******", :database=>"broadersheet_testing1"}, @query_cache_enabled=false, @connection=#<Mysql:0x23dc154>, @connection_options=["localhost", "root", "root", "broadersheet_testing1", nil, "/tmp/mysql.sock"]>, name=:reason, type=:string, limit=10, precision=nil, scale=nil, default=nil, null=false>, #<struct ActiveRecord::ConnectionAdapters::ColumnDefinition base=#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0x23d7eb0 @last_verification=0, @logger=#<Logger:0x1159a04 @level=0, @default_formatter=#<Logger::Formatter:0x11599c8 @datetime_format=nil>, @progname=nil, @logdev=#<Logger::LogDevice:0x11599a0 @filename="/Users/leem/Software/bsheet/log/webapp-development.log", @mutex=#<Logger::LogDevice::LogDeviceMutex:0x1159978 @mon_owner=nil, @mon_waiting_queue=[], @mon_entering_queue=[], @mon_count=0>, @dev=#<File:/Users/leem/Software/bsheet/log/webapp-development.log>, @shift_size=1048576, @shift_age=0>, @formatter=#<Logger::SimpleFormatter:0x263e744 @datetime_format=nil>>, @quoted_table_names={}, @runtime=428.263902664185, @quoted_column_names={:user_id=>"`user_id`", "suggestions_user_id_fkey"=>"`suggestions_user_id_fkey`", "id"=>"`id`"}, @config={:adapter=>"mysql", :username=>"root", :socket=>"/tmp/mysql.sock", :host=>"localhost", :password=>"*******", :database=>"broadersheet_testing1"}, @query_cache_enabled=false, @connection=#<Mysql:0x23dc154>, @connection_options=["localhost", "root", "root", "broadersheet_testing1", nil, "/tmp/mysql.sock"]>, name=:suggestion, type=:string, limit=200, precision=nil, scale=nil, default=nil, null=false>, #<struct ActiveRecord::ConnectionAdapters::ColumnDefinition base=#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0x23d7eb0 @last_verification=0, @logger=#<Logger:0x1159a04 @level=0, @default_formatter=#<Logger::Formatter:0x11599c8 @datetime_format=nil>, @progname=nil, @logdev=#<Logger::LogDevice:0x11599a0 @filename="/Users/leem/Software/bsheet/log/webapp-development.log", @mutex=#<Logger::LogDevice::LogDeviceMutex:0x1159978 @mon_owner=nil, @mon_waiting_queue=[], @mon_entering_queue=[], @mon_count=0>, @dev=#<File:/Users/leem/Software/bsheet/log/webapp-development.log>, @shift_size=1048576, @shift_age=0>, @formatter=#<Logger::SimpleFormatter:0x263e744 @datetime_format=nil>>, @quoted_table_names={}, @runtime=428.263902664185, @quoted_column_names={:user_id=>"`user_id`", "suggestions_user_id_fkey"=>"`suggestions_user_id_fkey`", "id"=>"`id`"}, @config={:adapter=>"mysql", :username=>"root", :socket=>"/tmp/mysql.sock", :host=>"localhost", , :database=>"broadersheet_testing1"}, @query_cache_enabled=false, @connection=#<Mysql:0x23dc154>, @connection_options=["localhost", "root", "root", "broadersheet_testing1", nil, "/tmp/mysql.sock"]>, name=:userinfo, type=:string, limit=80, precision=nil, scale=nil, default=nil, null=nil>, #<struct ActiveRecord::ConnectionAdapters::ColumnDefinition base=#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0x23d7eb0 @last_verification=0, @logger=#<Logger:0x1159a04 @level=0, @default_formatter=#<Logger::Formatter:0x11599c8 @datetime_format=nil>, @progname=nil, @logdev=#<Logger::LogDevice:0x11599a0 @filename="/Users/leem/Software/bsheet/log/webapp-development.log", @mutex=#<Logger::LogDevice::LogDeviceMutex:0x1159978 @mon_owner=nil, @mon_waiting_queue=[], @mon_entering_queue=[], @mon_count=0>, @dev=#<File:/Users/leem/Software/bsheet/log/webapp-development.log>, @shift_size=1048576, @shift_age=0>, @formatter=#<Logger::SimpleFormatter:0x263e744 @datetime_format=nil>>, @quoted_table_names={}, @runtime=428.263902664185, @quoted_column_names={:user_id=>"`user_id`", "suggestions_user_id_fkey"=>"`suggestions_user_id_fkey`", "id"=>"`id`"}, @config={:adapter=>"mysql", :username=>"root", :socket=>"/tmp/mysql.sock", :host=>"localhost", , :database=>"broadersheet_testing1"}, @query_cache_enabled=false, @connection=#<Mysql:0x23dc154>, @connection_options=["localhost", "root", "root", "broadersheet_testing1", nil, "/tmp/mysql.sock"]>, name=:actioned, type=:datetime, limit=nil, precision=nil, scale=nil, default=nil, null=nil>, #<struct ActiveRecord::ConnectionAdapters::ColumnDefinition base=#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0x23d7eb0 @last_verification=0, @logger=#<Logger:0x1159a04 @level=0, @default_formatter=#<Logger::Formatter:0x11599c8 @datetime_format=nil>, @progname=nil, @logdev=#<Logger::LogDevice:0x11599a0 @filename="/Users/leem/Software/bsheet/log/webapp-development.log", @mutex=#<Logger::LogDevice::LogDeviceMutex:0x1159978 @mon_owner=nil, @mon_waiting_queue=[], @mon_entering_queue=[], @mon_count=0>, @dev=#<File:/Users/leem/Software/bsheet/log/webapp-development.log>, @shift_size=1048576, @shift_age=0>, @formatter=#<Logger::SimpleFormatter:0x263e744 @datetime_format=nil>>, @quoted_table_names={}, @runtime=428.263902664185, @quoted_column_names={:user_id=>"`user_id`", "suggestions_user_id_fkey"=>"`suggestions_user_id_fkey`", "id"=>"`id`"}, @config={:adapter=>"mysql", :username=>"root", :socket=>"/tmp/mysql.sock", :host=>"localhost", , :database=>"broadersheet_testing1"}, @query_cache_enabled=false, @connection=#<Mysql:0x23dc154>, @connection_options=["localhost", "root", "root", "broadersheet_testing1", nil, "/tmp/mysql.sock"]>, name=:user_id, type=:integer, limit=11, precision=nil, scale=nil, default=nil, null=nil>, #<struct ActiveRecord::Connectio
nAdapters::ColumnDefinition base=#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0x23d7eb0 @last_verification=0, @logger=#<Logger:0x1159a04 @level=0, @default_formatter=#<Logger::Formatter:0x11599c8 @datetime_format=nil>, @progname=nil, @logdev=#<Logger::LogDevice:0x11599a0 @filename="/Users/leem/Software/bsheet/log/webapp-development.log", @mutex=#<Logger::LogDevice::LogDeviceMutex:0x1159978 @mon_owner=nil, @mon_waiting_queue=[], @mon_entering_queue=[], @mon_count=0>, @dev=#<File:/Users/leem/Software/bsheet/log/webapp-development.log>, @shift_size=1048576, @shift_age=0>, @formatter=#<Logger::SimpleFormatter:0x263e744 @datetime_format=nil>>, @quoted_table_names={}, @runtime=428.263902664185, @quoted_column_names={:user_id=>"`user_id`", "suggestions_user_id_fkey"=>"`suggestions_user_id_fkey`", "id"=>"`id`"}, @config={:adapter=>"mysql", :username=>"root", :socket=>"/tmp/mysql.sock", :host=>"localhost", , :database=>"broadersheet_testing1"}, @query_cache_enabled=false, @connection=#<Mysql:0x23dc154>, @connection_options=["localhost", "root", "root", "broadersheet_testing1", nil, "/tmp/mysql.sock"]>, name=:created_at, type=:datetime, limit=nil, precision=nil, scale=nil, default=nil, null=false>, #<struct ActiveRecord::ConnectionAdapters::ColumnDefinition base=#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0x23d7eb0 @last_verification=0, @logger=#<Logger:0x1159a04 @level=0, @default_formatter=#<Logger::Formatter:0x11599c8 @datetime_format=nil>, @progname=nil, @logdev=#<Logger::LogDevice:0x11599a0 @filename="/Users/leem/Software/bsheet/log/webapp-development.log", @mutex=#<Logger::LogDevice::LogDeviceMutex:0x1159978 @mon_owner=nil, @mon_waiting_queue=[], @mon_entering_queue=[], @mon_count=0>, @dev=#<File:/Users/leem/Software/bsheet/log/webapp-development.log>, @shift_size=1048576, @shift_age=0>, @formatter=#<Logger::SimpleFormatter:0x263e744 @datetime_format=nil>>, @quoted_table_names={}, @runtime=428.263902664185, @quoted_column_names={:user_id=>"`user_id`", "suggestions_user_id_fkey"=>"`suggestions_user_id_fkey`", "id"=>"`id`"}, @config={:adapter=>"mysql", :username=>"root", :socket=>"/tmp/mysql.sock", :host=>"localhost", , :database=>"broadersheet_testing1"}, @query_cache_enabled=false, @connection=#<Mysql:0x23dc154>, @connection_options=["localhost", "root", "root", "broadersheet_testing1", nil, "/tmp/mysql.sock"]>, name=:updated_at, type=:datetime, limit=nil, precision=nil, scale=nil, default=nil, null=nil>, CONSTRAINT `suggestions_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES users (`id`)) ENGINE=InnoDB
(See full trace by running task with --trace)
Process finished with exit code 1
I used to use mig_constraints as well, but it looks like its functionality is included in the oracle_enhanced adapter now, along with a lot of other goodies. Check out http://github.com/rsim/oracle-enhanced/blob/master/History.txt for details.
FYI, from my testing, mig-constraints breaks between AR 2.3.3 and 2.3.4. Since I’m not on Oracle and I want more than foreign key constraints, I’ll probably look into the changes with 2.3.4 and see if I can fix the plugin.
FYI, I finally got around to fixing mig_constraints. So far I have create_table working as expected, but not add_constraint or drop_constraint.
http://github.com/jlw/mig_constraints