迁移失败

时间:2014-05-02 13:09:05

标签: ruby-on-rails activerecord migration

我有两个迁移.. self.down方法在一个上失败并在另一个上工作,即使它们看起来与我相同(不同的表,相同的列和类型。)如果我用“varchar”替换:string )“它有效,但我不明白为什么:在这种情况下字符串会失败。

有人可以看到我可能做错了吗?

我在OSX上使用Rails / ActiveRecord 2.1.0和Mysql 5.6.13

这个失败了。

  def self.down
    remove_column :comments, :employee_id
    add_column :comments, :employee_id, :string #"varchar(255)" will work 
    Comment.all.each do |c|
      c.employee_id = c.empno
      c.send(:update_without_callbacks)
     end
    remove_column :comments, :empno
  end

这个有效

  def self.down
    remove_column :supervisor_options, :employee_id
    add_column :supervisor_options, :employee_id, :string
    SupervisorOption.all.each do |c|
      c.employee_id = c.empno
      c.send(:update_without_callbacks)
     end
    remove_column :supervisor_options, :empno
  end

我在db:migrate期间获得的堆栈是......

rake aborted!
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 '(255)' at line 1: ALTER TABLE `comments` ADD `employee_id` varchar(255)(255)
/Users/gakins/.rvm/gems/ree-1.8.7-2012.02@gaimplan/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:147:in `log'
/Users/gakins/.rvm/gems/ree-1.8.7-2012.02@gaimplan/gems/activerecord-mysql2-adapter-0.0.3/lib/active_record/connection_adapters/mysql2_adapter.rb:265:in `execute'
/Users/gakins/.rvm/gems/ree-1.8.7-2012.02@gaimplan/gems/activerecord-mysql2-adapter-0.0.3/lib/active_record/connection_adapters/mysql2_adapter.rb:450:in `add_column'
/Users/gakins/.rvm/gems/ree-1.8.7-2012.02@gaimplan/gems/activerecord-2.1.0/lib/active_record/migration.rb:330:in `send'
/Users/gakins/.rvm/gems/ree-1.8.7-2012.02@gaimplan/gems/activerecord-2.1.0/lib/active_record/migration.rb:330:in `method_missing'
/Users/gakins/.rvm/gems/ree-1.8.7-2012.02@gaimplan/gems/activerecord-2.1.0/lib/active_record/migration.rb:310:in `say_with_time'
/Users/gakins/.rvm/gems/ree-1.8.7-2012.02@gaimplan/gems/activerecord-2.1.0/lib/active_record/migration.rb:310:in `say_with_time'
/Users/gakins/.rvm/gems/ree-1.8.7-2012.02@gaimplan/gems/activerecord-2.1.0/lib/active_record/migration.rb:326:in `method_missing'
./db/migrate//20140501155627_rename_employee_id.rb:17:in `down_without_benchmarks'
/Users/gakins/.rvm/gems/ree-1.8.7-2012.02@gaimplan/gems/activerecord-2.1.0/lib/active_record/migration.rb:264:in `send'
/Users/gakins/.rvm/gems/ree-1.8.7-2012.02@gaimplan/gems/activerecord-2.1.0/lib/active_record/migration.rb:264:in `migrate'
/Users/gakins/.rvm/gems/ree-1.8.7-2012.02@gaimplan/gems/activerecord-2.1.0/lib/active_record/migration.rb:264:in `migrate'
/Users/gakins/.rvm/gems/ree-1.8.7-2012.02@gaimplan/gems/activerecord-2.1.0/lib/active_record/migration.rb:430:in `migrate'
/Users/gakins/.rvm/gems/ree-1.8.7-2012.02@gaimplan/gems/activerecord-2.1.0/lib/active_record/migration.rb:420:in `each'
/Users/gakins/.rvm/gems/ree-1.8.7-2012.02@gaimplan/gems/activerecord-2.1.0/lib/active_record/migration.rb:420:in `migrate'
/Users/gakins/.rvm/gems/ree-1.8.7-2012.02@gaimplan/gems/activerecord-2.1.0/lib/active_record/migration.rb:361:in `down'
/Users/gakins/.rvm/gems/ree-1.8.7-2012.02@gaimplan/gems/activerecord-2.1.0/lib/active_record/migration.rb:341:in `migrate'
/Users/gakins/.rvm/gems/ree-1.8.7-2012.02@gaimplan/gems/rails-2.1.0/lib/tasks/databases.rake:99

0 个答案:

没有答案