Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rake与我的数据库不同步_Ruby On Rails_Database_Rake - Fatal编程技术网

Ruby on rails Rake与我的数据库不同步

Ruby on rails Rake与我的数据库不同步,ruby-on-rails,database,rake,Ruby On Rails,Database,Rake,我继承了一个RubyonRails项目,其中程序员没有使用rake创建db模式,因此它看起来非常不同步,有没有办法纠正这个问题?首先创建一个schema.rb文件 rakedb:schema:dump 然后对它进行迁移 class CreateMigration < ActiveRecord::Migration def self.up # insert schema.rb here end def self.down end end class-CreateM

我继承了一个RubyonRails项目,其中程序员没有使用rake创建db模式,因此它看起来非常不同步,有没有办法纠正这个问题?

首先创建一个schema.rb文件

rakedb:schema:dump

然后对它进行迁移

class CreateMigration < ActiveRecord::Migration
  def self.up
    # insert schema.rb here
  end

  def self.down
  end
end
class-CreateMigration

您可能还需要创建schema_migrations表,并手动将此迁移的时间戳添加到该表中

您不需要将模式放在迁移中,它将放在
db/schema.rb
中,这已经足够好了,因为人们可以使用
rake db:schema:load
加载它。这样就可以存在“初始”迁移,也可以使用rake db:migrate重新开始。