简体   繁体   中英

ruby rails migrate is not updating database

I ran into something with a rails project where migrations don't seem to be affecting the database/tables.

Rails 4/ Ruby 2.0 / Sqllite / development version

Previously if I set up a migration, the results would reflect in the database and tables (using an sqlite data browser)

Now, when I create a migration, it runs with an error code of 0 but nothing in the database changes. for example, if I set up this migration and run Rake d:migrate, nothing is added to the database.

class CreateTestModel < ActiveRecord::Migration
  def change

      def up
        create_table :products do |t|
          t.string :name
          t.text :description

          t.timestamps
        end
      end

      def down
        drop_table :products
      end


  end
end

rake migrate runs with an error code of 0

C:\\Ruby200\\bin\\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/Users/cmendla/RubymineProjects/Rl2/bin/rake db:migrate C:/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.2.4/lib/action_dispatch/http/mime_type.rb:163: warning: already initialized constant Mime::PDF C:/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.2.4/lib/action_dispatch/http/mime_type.rb:163: warning: previous definition of PDF was here C:/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.2.4/lib/action_dispatch/http/mime_type.rb:163: warning: already initialized constant Mime::BMP C:/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.2.4/lib/action_dispatch/http/mime_type.rb:163: warning: previous definition of BMP was here C:/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.2.4/lib/action_dispatch/http/mime_type.rb:163: warning: already initialized constant Mime::JPEG C:/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.2.4/lib/action_dispatch/http/mime_type.rb:163: warning: previous definition of JPEG was here C: /Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.2.4/lib/action_dispatch/http/mime_type.rb:163: warning: already initialized constant Mime::JPG C:/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.2.4/lib/action_dispatch/http/mime_type.rb:163: warning: previous definition of JPG was here C:/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.2.4/lib/action_dispatch/http/mime_type.rb:163: warning: already initialized constant Mime::GIF C:/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.2.4/lib/action_dispatch/http/mime_type.rb:163: warning: previous definition of GIF was here == 20151015154920 CreateTestModel: migrating ================================== == 20151015154920 CreateTestModel: migrated (0.0000s) =========================

Process finished with exit code 0

I suspect that perhaps the sql database is locked. I did reboot my laptop by that didn't work either.

NOTE - I had a lot of messed up migrations. I tried to straighten things out by deleting some of the later migrations and unused datatables. Not sure if that is causing the problem.

Change to

class CreateTestModel < ActiveRecord::Migration
  def change
    create_table :products do |t|
      t.string :name
      t.text :description
      t.timestamps
    end
  end
end

Or

class CreateTestModel < ActiveRecord::Migration
  def up
    create_table :products do |t|
      t.string :name
      t.text :description
      t.timestamps
    end
  end

  def down
    drop_table :products
  end

end

Pretty certain your issue is having the up and down methods within a change one.

Then rerun the migration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM