1

I have a error without explanation.

My error :

G::UndefinedColumn: ERROR:  column "conjoncture_index_id" referenced in foreign key constraint does not exist
: ALTER TABLE "reports" ADD CONSTRAINT "fk_rails_c25ad9a112"
FOREIGN KEY ("conjoncture_index_id")
  REFERENCES "conjoncture_indices" ("id")

My migration :

class AddColumnToReports < ActiveRecord::Migration
  def change
    add_reference :reports, :conjoncture_indice, index: true
    add_foreign_key :reports, :conjoncture_indices
  end
end

My create table migration :

class CreateConjonctureIndices < ActiveRecord::Migration
  def change
    create_table :conjoncture_indices do |t|
      t.date :date
      t.float :value

      t.timestamps null: false
    end
  end
end

My model :

class ConjonctureIndice < ActiveRecord::Base
    has_many :reports
    by_star_field :date
end

My ConjonctureIndice shema.rb part :

  create_table "conjoncture_indices", force: :cascade do |t|
    t.date     "date"
    t.float    "value"
    t.datetime "created_at",                 null: false
    t.datetime "updated_at",                 null: false
  end

I'm looking for "conjoncture_index" in my project but nothing... I think that a old version of the project uses "conjoncture_index" instead "conjoncture_indice" but all occurence are deleted.

5
  • Can you post the schema.rb of the ConjonctureIndice part Commented Jun 1, 2015 at 10:12
  • I fear that the naming is indeed the problem , apart from that everything looks ok . Can you rename and check it ? Commented Jun 1, 2015 at 10:55
  • Just name it Conjoncture and remove the index and indice part Commented Jun 1, 2015 at 10:56
  • I rename all occurence of ConjonctureIndice to Conjoncture and always the same error "G::UndefinedColumn: ERROR: column "confidence_index_id" referenced in foreign key constraint does not exist" Commented Jun 1, 2015 at 11:21
  • Is there a kind of cache for activerecord ? He would use for migration ... Because in my project there is nowhere refers to this "index" Commented Jun 1, 2015 at 11:23

2 Answers 2

5

In rails , The migration names are plural whereas the model names are singular . So the model name should had been Index but it cannot be as it's a reserved keyword , the plural of which transforms to ConjunctureIndices .

Note - If you are still in doubt , then you can drop and re-create the database but i suspect the naming convention to be an issue in your case .

Sign up to request clarification or add additional context in comments.

1 Comment

Rename and migrate again , let me know what happens then
0

Ok i found the problem. i think that the error message is the same as before but he refer to a other table called "confidence_indices". The error come from "indice" word.. when i delete it i have no problem.

1 Comment

Glad you were able to find it .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.