Ruby   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ruby-on-rails – 奇怪的Rails迁移/ schema.rb问题大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
一会儿我运行了以下迁移:
class CreatePipelinespecs < ActiveRecord::Migration
  def change
    create_table :pipeline_specs do |t|
      t.Integer :id_no
      t.String :od
      t.String :wt
      t.String :material
      t.String :spec_type
      t.String :spec_grade
      t.String :mop
      t.String :stress_level
      t.String :joints
      t.text :notes
      t.String :ip
      t.references :pipeline,index: true,foreign_key: false

      t.timestamps null: false
    end
    add_index :pipeline_specs,:id_no
  end
end

我不知道现在发生了什么,但是每次运行rake db时,迁移scheR_632_11845@e.rb文件将被更新

create_table "pipeline_specs",force: :cascade do |t|
    t.Integer  "id_no"
    t.String   "od"
    t.String   "wt"
    t.String   "material"
    t.String   "spec_type"
    t.String   "spec_grade"
    t.String   "mop"
    t.String   "stress_level"
    t.String   "joints"
    t.text     "notes"
    t.String   "ip"
    t.Integer  "pipelines_id"
    t.datetiR_632_11845@e "created_at",null: false
    t.datetiR_632_11845@e "updated_at",null: false
  end

  add_index "pipeline_specs",["id_no"],name: "index_pipeline_specs_on_id_no",using: :btree
  add_index "pipeline_specs",["pipelines_id"],name: "index_pipeline_specs_on_pipelines_id",using: :btree

注意复数pipelines_id.实际的数据库表(dev,production等)都是pipeline_id,因为参表是Pipeline是正确的.所以我添加了一个新的不相关的迁移,并且scheR_632_11845@a.rb被更新,并且在我改回它们之后,这些更改再次变回复数.如果我在运行测试时忘记更改它们,那么错误的模式会被加载到测试环境中,所有的内容都会中断.

我在这里亏了我在这里遗漏了一些明显的东西,还是有一些隐藏的迁移模式表等.

唯一认为我可以这样做的是当我使用原始迁移我使用管道:引用vs管道:引用,然后修复我的错误,然后在提交之前清理迁移并部署它.

任何想法在这里为什么这是发生和如何解决它一劳永逸

updatE

这是我的三个相关型号:

irb(main):031:0> Pipeline
=> Pipeline(id: Integer,licence: String,company: String,company_id: Integer,ba_code: String,substance_code: String,substance: String,h2s: String,partial_pressure: String,notes: text,created_at: datetiR_632_11845@e,updated_at: datetiR_632_11845@e,slug: String)
irb(main):032:0> Pipelinespec
=> Pipelinespec(id: Integer,id_no: Integer,od: String,wt: String,material: String,spec_type: String,spec_grade: String,mop: String,stress_level: String,joints: String,ip: String,pipeline_id: Integer,slug: String)
irb(main):033:0> Pipelinesegment
=> Pipelinesegment(id: Integer,line: Integer,lsd_from: Integer,sec_from: Integer,twp_from: Integer,rge_from: Integer,m_from: Integer,fc_from: String,lsd_to: Integer,sec_to: Integer,twp_to: Integer,rge_to: Integer,m_to: Integer,fc_to: String,length: String,aasm_state: String,state_comment: String,state_user_id: Integer,aasm_date: datetiR_632_11845@e,env: String,volume: String,pipeline_spec_id: Integer,slug: String)

Pipeline has_many Pipelinespec和Pipelinesegment. Pipelinesegment has_one Pipelinespec.

更新2

检查了我的测试环境架构 – 没关系Ran rake db:migrate,并再次scheR_632_11845@a.rb更新.再次运行测试,并得到gobs:

ActiveRecord::StatemenTinvalid:         ActiveRecord::StatemenTinvalid: PG::Undefinedcolumn: ERROR:  column "pipeline_id" of relation "pipeline_specs" does not exist
        LINE 1: ...,"mop","stress_level","joints","notes","ip","pipeline_...
                                                                     ^
        : INSERT INTO "pipeline_specs" ("id","id_no","od","wt","material","spec_type","spec_grade","pipeline_id","created_at","updated_at") VALUES (1,1,'88.9','3.18','S','Z245.1','359 2','9930','25','W','myText','U','2017-04-24 03:47:26','2017-04-24 03:47:26')

因为灯具试图加载到刚刚在测试时刻加载的不正确的测试架构.

@H_696_32@

解决方法

我认为,因为您删除的迁移没有在测试环境中运行,请尝试通过以下方式重置测试数据库:
RAILS_ENV=test rake db:migrate:reset
@H_696_32@ @H_696_32@

大佬总结

以上是大佬教程为你收集整理的ruby-on-rails – 奇怪的Rails迁移/ schema.rb问题全部内容,希望文章能够帮你解决ruby-on-rails – 奇怪的Rails迁移/ schema.rb问题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。