ruby rails 迁移未更新数据库
ruby rails migrate is not updating database
我 运行 进入了一个 rails 项目,其中迁移似乎没有影响 database/tables。
Rails4/Ruby2.0/Sqllite/开发版
以前如果我设置迁移,结果会反映在数据库和表中(使用 sqlite 数据浏览器)
现在,当我创建迁移时,它 运行 的错误代码为 0,但数据库中没有任何变化。
例如,如果我设置此迁移和 运行 Rake d:migrate,则不会向数据库添加任何内容。
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 迁移 运行s,错误代码为 0
C:\Ruby200\bin\ruby.exe -e
$stdout.sync=true;$stderr.sync=true;load([=13=]=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
我怀疑 sql 数据库可能被锁定了。我确实重启了我的笔记本电脑,但它也不起作用。
注意 - 我有很多混乱的迁移。我试图通过删除一些后来的迁移和未使用的数据表来理顺事情。不确定这是否导致了问题。
改为
class CreateTestModel < ActiveRecord::Migration
def change
create_table :products do |t|
t.string :name
t.text :description
t.timestamps
end
end
end
或
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
很确定您的问题是在更改方法中使用 up 和 down 方法。
然后重新运行迁移。
我 运行 进入了一个 rails 项目,其中迁移似乎没有影响 database/tables。
Rails4/Ruby2.0/Sqllite/开发版
以前如果我设置迁移,结果会反映在数据库和表中(使用 sqlite 数据浏览器)
现在,当我创建迁移时,它 运行 的错误代码为 0,但数据库中没有任何变化。 例如,如果我设置此迁移和 运行 Rake d:migrate,则不会向数据库添加任何内容。
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 迁移 运行s,错误代码为 0
C:\Ruby200\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load([=13=]=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
我怀疑 sql 数据库可能被锁定了。我确实重启了我的笔记本电脑,但它也不起作用。
注意 - 我有很多混乱的迁移。我试图通过删除一些后来的迁移和未使用的数据表来理顺事情。不确定这是否导致了问题。
改为
class CreateTestModel < ActiveRecord::Migration
def change
create_table :products do |t|
t.string :name
t.text :description
t.timestamps
end
end
end
或
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
很确定您的问题是在更改方法中使用 up 和 down 方法。
然后重新运行迁移。